Home > ASP.Net, Javascript > Custom validator for Group of RadioButtons

Custom validator for Group of RadioButtons


Try this example:

<script type="text/javascript">

function ValidateRadios(oSrc, args)
{

var rpta = false;for(i = 1; i<=5 ; i++)
{

if(document.getElementById("loc" + i).checked == true)
{

rpta = true;
}

}

args.IsValid = rpta;

}

</script>

<asp:RadioButton ID="loc1" runat="server" ValidationGroup="location" />

<asp:RadioButton ID="loc2" runat="server" ValidationGroup="location" />

<asp:RadioButton ID="loc3" runat="server" ValidationGroup="location" />

<asp:RadioButton ID="loc4" runat="server" ValidationGroup="location" />

<asp:RadioButton ID="loc5" runat="server" ValidationGroup="location" />

<asp:Button ID="Button1" ValidationGroup="location" runat="server" Text="Button" />

<br />

<asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="location"
ErrorMessage="Please select one of the radio button"
ClientValidationFunction="ValidateRadios" Display="Dynamic" OnServerValidate="validateLoc" ></asp:CustomValidator>

Good Luck

Advertisements
Categories: ASP.Net, Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: