ASP.Net Quick Validation Examples

Here are just a couple quick code snippets showing ASP.Net form validation. If you have any questions or want a more detailed example just leave me a comment and I’ll put up a more verbose post.


This is an example of a custom function to use against a custom made validation tag.

protected void verifyUniqueEmail(object sender, ServerValidateEventArgs e)
{
// querying SQL Server here...
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
{
Debug.WriteLine("email address: " + txbemail.Text + " seen " + rdr["emailcount"].ToString() + " times.");
if (Convert.ToInt32(rdr["emailcount"]) > 0)
{
e.IsValid = false;
}
else
{
e.IsValid = true;
}
}
}