title: Client side custom validator for radio buttons
body: <p>I am facing problem regarding validating radiobutton at client side named as "male", "female". I dont want to use radiobutton list, Could anyone please check my code and rectify it? Thanks.  </p>
  
  <p><strong>Here is .aspx page:</strong></p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript" &gt;
  
                  function ClientValidate(source, e) {
                      if (document.getElementById("content_radmale").checked == true || document.getElementById("content_radfemale").checked == true) {
                          e.IsValid = true;
                      }
                      else {
                          e.IsValid = false;
                      }
                    //  alert("Enter gender  !");
                  }
  &lt;/script&gt;
      &lt;asp:CustomValidator ID="CustomValidator1" runat="server" 
              ErrorMessage="please enter any option" ClientValidationFunction = "ClientValidate"
          ValidationGroup="gender" ControlToValidate="txtname"&gt;&lt;/asp:CustomValidator&gt;
  </code></pre>
  
  <p><strong>And .cs page:</strong></p>
  
  <pre><code>    string gender = radmale.Text;
  
      if (radfemale.Checked)
      {
          gender = radfemale.Text;
  
      }
      CustomValidator1.Validate(); 
      string sql = "INSERT INTO registration(emailaddress,username,password,name,gender)VALUES ('"+email+"','"+username+"','"+pass+"','"+name+"','"+gender+"')  ";
      SqlCommand cmd = new SqlCommand(sql, con);
  
      con.Open();
  
      cmd.ExecuteNonQuery();
  
     con.Close();
  </code></pre>