Suppose you have 3 Radiobuttons.. You will be validating on some button control. Please find below how to do it step by step.
Step1: Setup your radio buttons on aspx page.
<strong> Some Heading</strong>
<asp:RadioButtonID="Radio1"GroupName="Flag"runat="server"Text="DNR"/>
<asp:RadioButtonID="Radio2"GroupName="Flag"runat="server"Text="RE"/>
<asp:RadioButtonID="Radio3"GroupName="Flag"runat="server"Text="RI"/>
Step2: You have to declare some button/imagebutton or somthing else to validate. I suppose you have button cmdSave for validation.
Step3: in code behind of page On Page Load, you have to call javascript function of validation. i.e
cmdSave.Attributes.Add(
"onClick","Javascript:checkFlag()");
Step4: You have to declare function checkFlag() in your aspx page. i.e
function
checkFlag()
{
event.returnValue =false;
var DNR = document.getElementById('<%= RadioDNR.ClientID %>').checked;
var RE = document.getElementById('<%= RadioRE.ClientID %>').checked;
var RI = document.getElementById('<%= RadioRI.ClientID %>').checked;
if (DNR == false && RE == false && RI ==false)
{
alert (
'Please Specify one of the Flags');
}
else
{
event.returnValue =true;
}
}
You have to do nothing else. I am sure it will resolve your problem. If this is the solution of your problem, please mark this post as resolved. Thanks