Client-side validation?

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.
 
B

Brock Allen

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
 
D

dan.c.roth

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top