I'm fairly new to C# and visual studio however have a problem.
I have 10 Radio buttons within one group box. I need to confirm one of these radio buttons is selected before continuing the code. And if one is not selected then a message box pop-up to ask user to select a radio button.
Can anyone help with this?
You could do this in two ways.
The first way is the back-end validation
. Ie, after the form is submitted.
Eg:
if(FormModel.RadioButton != null || FormModel.RadioButton != "")
//this can be used(For MVC in the Action Method)
The second way is, the client-side/Front-end validation(JavaScript validation)
.
eg:
<script language="javascript">
function ClientValidate() //To be called during submit button-click
{
if ($('#RadioButton1').checked //Where RadioButton1 is the Id of the first element
|| $('#RadioButton2').checked ) {
arguments.IsValid = true;
} else {
arguments.IsValid = false;
}
}
</script>
hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.