How to validate a CheckBox

Platform: ASP.NET| Category: CheckBox

<asp:CheckBox runat='server' id='chkbox'></asp:CheckBox>
<asp:CustomValidator runat='server' ErrorMessage='Error!' OnServerValidate='ServerValidation' ClientValidationFunction='ClientValidation'
		ID='Customvalidator1' />
<asp:Button runat='server' text='submit' ID='Button1' />

<script language='javascript'> 
function ClientValidation(source, args) 
{ 
	args.IsValid = document.all['chkbox'].checked; 
} 
</script>

VB.NET


<script runat='server' language='vb'> 
sub ServerValidation( source as object, args as ServerValidateEventArgs ) 
	args.IsValid = chkbox.Checked 
end sub 
</script>

C#


<script runat='server' language='cs'> 
void ServerValidation(object source, ServerValidateEventArgs args) 
{ 
	args.IsValid = chkbox.Checked; 
} 
</script>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.