JQuery Validate RadioButtonList in Asp.Net Example

JQuery Validate RadioButtonList in Asp.Net Example

I will explain how to validate Radiobuttonlist using Jquery using Asp.net.

Script For Validation

<script type=”text/javascript”>
$(document).ready(function () {
$(‘input[id$=btnSave]’).click(function () {
var v = $(‘[id$=radGender] input:checked’).length;
if (v == 0) {
alert(‘Please Select Gender’);
return false;
}
else {
var genVal = $(‘[id$=radGender] input:checked’).val();
}

});

});
</script>
Design Page :

<table style=”margin: 0 auto”>

<tr>
<td>
Gender::
</td>
<td>
<asp:RadioButtonList ID=”radGender” runat=”server”>
<asp:ListItem Value=”Male”></asp:ListItem>
<asp:ListItem Value=”Female”></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>

<tr>
<td colspan=”2″>
<asp:Button ID=”btnSave” runat=”server” Text=”Save” />
</td>

</tr>

If you observe above code in header section I added script file link by using that file we have a chance to interact with JQuery and in the script we have btnSave button click function which is used to validate radiobuttonlist using JQuery in asp.net.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply