Tim Maxey .NET Technology Blog & Resources

JavaScript CheckBox Validate with .NET

The Code on the Client:

<script language=javascript>
function validate(chkid){
  if (document.getElementById(chkid).checked){
    return true;
    }
  else {
    alert("You didn't check the box...")
    return false;
  }
}
</script>

Now on your Button Control on the form OnLoad event add this:

If Not Page.IsPostBack Then
         

 
            Button1.Attributes.Add("onClick", "return validate('" & CheckBox1.ClientID & "');")

End If


Feedback

No comments posted yet.


Post a comment





 

Please add 4 and 6 and type the answer here: