Introduction:
Description:
In previous articles I explained validate email address using JQuery, how to disable or enable all the controls on page using JQuery , validate phone number using JQuery and many articles relating to JQuery. Now I will explain how to validate radiobuttonlist using JQuery in asp.net.
In previous articles I explained validate email address using JQuery, how to disable or enable all the controls on page using JQuery , validate phone number using JQuery and many articles relating to JQuery. Now I will explain how to validate radiobuttonlist using JQuery in asp.net.
To implement this one we need to write code as shown below in your aspx page
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Validate asp.net radiobuttonlist in JQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function()
{
$('#btnSubmit').click(function() {
if ($('#rdbtnGender
:radio:checked').length > 0) {
return true;
}
else {
alert('Please
select Gender')
return false;
}
})
})
</script>
</head>
<body>
<form id="form1"
runat="server">
<div>
<table>
<tr>
<td> <b>Select
Gender:</b></td>
<td>
<asp:RadioButtonList ID="rdbtnGender"
runat="server"
RepeatDirection="Horizontal">
<asp:ListItem Value="1" Text="Male" />
<asp:ListItem Value="2" Text="Female" />
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit"
Text="Submit"
runat="server"
/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
|
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 btnSubmit button click function
which is used to validate radiobuttonlist using JQuery in asp.net.
Demo
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||

Subscribe by RSS
Subscribe by Email
2 comments :
$("#<%= Button1.ClientID %>").click(function () {
var groups = {}
$(":radio").each(function () {
groups[this.name] = true;
});
for (group in groups) {
var radioButttons = $(":radio[name=" + group + "]:checked");
isChecked = !!radioButttons.length;
if (!isChecked) {
$(":radio[name=" + group + "]").next("label").css("background-color", "blue");
}
else {
$(":radio[name=" + group + "]").next("label").css("background-color", "white");
}
}
return false;
});
Nice bro great
Note: Only a member of this blog may post a comment.