Client-side validation?

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

How would I go about validating on the client side before a post back? I do
it now in the code with something like "if TextBox.Text="" then..." I'd
like to do it on the client but I've never been any good at html or jscript.
 
There are a set of validation controls you can use that do client side validation,
such as RequiredField, Compare, Range, and RegularExpression validators.
If you're using ASP.NET v1.1 then the client side validation only works with
IE as the browser. If you're using v2.0 then they're supposed to work with
any browser (crud, another thing for me to go test). The validation controls
always do server side validation for security reasons. They help eliminate
80% of the tedious standard validation code that's common in web apps. For
the other 20% there is the Custom validator where you can build more elaborate
validation logic custom for your application.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Hi

For client side validation you could do (for example) something like

In the code behind load event:

txtShiftNumber.Attributes.Add("onkeypress","ValidateNumeric(\"txtShiftNumber\")");

And in the Web page script:

function ValidateNumeric(id)
{
if (window.event.keyCode > 57 || window.event.keyCode < 48 )
{
window.event.returnValue = false; return;
}
}

Regards,
Daniel Roth
MCSD.NET
 
Back
Top