Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have ten RadioButtonList in my aspx page. I want to validate each of them before/on clicking the submit button. Javascript could also work with me. Can anyone help?

Thanks in advance.
Posted
Comments
Nelek 7-Jan-14 6:42am    
Tejas Vaishnav 7-Jan-14 8:16am    
what have you tried so far? if you are stuck at any place then please share your code, so it will verify and modified to get it in working condition..
also one more thing which type of validation you want.. required or any thing else..?
code_shines 7-Jan-14 9:03am    
i haven't tried anything significant yet. validation is on atleast 1 radio button being checked for evry list. since each button has a value, that are to be added after submitting the form.

here's some code
<pre lang="xml">asp:RadioButtonList ID="r1" runat="server">
<asp:ListItem ID="a1" Value="1" runat="server" Text="option 1" />
<asp:ListItem ID="b1" Value="2" runat="server" Text="option 2" />
<asp:ListItem ID="c1" Value="3" runat="server" Text="option 3" />
</asp:RadioButtonList>

asp:RadioButtonList ID="r1" runat="server">
<asp:ListItem ID="a1" Value="1" runat="server" Text="option 1" />
<asp:ListItem ID="b1" Value="2" runat="server" Text="option 2" />
<asp:ListItem ID="c1" Value="3" runat="server" Text="option 3" />
</asp:RadioButtonList>

</pre>
.. upto 8 more of such lists

PS: i'm new C# ;)

1 solution

use 'args.IsValid' in javascript to validate if any radio button in radiobuttonlist is checked..


function ValidateModuleList(source, args) {
var gridview = document.getElementById('<%= grdmygridview.ClientID %>');
if (gridview != null) {
document.getElementById('<%= lblMessage.ClientID %>').style.display = 'inherit';
args.IsValid = true;
}
else
{
document.getElementById('<%= lblMessage.ClientID %>').style.display = 'none';
args.IsValid = false;
}
}

sample code..



edit conditions as u need and put this function in customvalidator below ur list..

(ClientValidationFunction="ValidateModuleList")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900