Apply validation radio button list using JavaScript in asp.net
function ValidateRadioButtonList(source, arguments) {
var RBL = document.getElementById(source.controltovalidate);
var radiobuttonlist = RBL.getElementsByTagName("input");
var counter = 0;
var atLeast = 1
for (var i = 0; i < radiobuttonlist.length; i++) {
if (radiobuttonlist[i].checked) {
counter++;
}
}
if (atLeast = counter) {
arguments.IsValid = true;
return arguments.IsValid;
}
arguments.IsValid = false;
return arguments.IsValid;
}
<asp:RadioButtonList ID="rblCOBC" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
<asp:CustomValidator runat="server" Display="Dynamic" ValidateEmptyText="true" ClientValidationFunction="ValidateRadioButtonList"
ID="CtmrblCOBC" ValidationGroup="gpAddUser" ControlToValidate="rblCOBC" ErrorMessage="Required"></asp:CustomValidator>
function ValidateRadioButtonList(source, arguments) {
var RBL = document.getElementById(source.controltovalidate);
var radiobuttonlist = RBL.getElementsByTagName("input");
var counter = 0;
var atLeast = 1
for (var i = 0; i < radiobuttonlist.length; i++) {
if (radiobuttonlist[i].checked) {
counter++;
}
}
if (atLeast = counter) {
arguments.IsValid = true;
return arguments.IsValid;
}
arguments.IsValid = false;
return arguments.IsValid;
}
<asp:RadioButtonList ID="rblCOBC" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
<asp:CustomValidator runat="server" Display="Dynamic" ValidateEmptyText="true" ClientValidationFunction="ValidateRadioButtonList"
ID="CtmrblCOBC" ValidationGroup="gpAddUser" ControlToValidate="rblCOBC" ErrorMessage="Required"></asp:CustomValidator>
No comments:
Post a Comment