Need Help Understanding Validation

J

Jonathan Wood

I'm new to ASP .NET and need help understanding validation.

I have a large VB .NET Web application that is working and I'd like to add
some validation to some additional fields. But I'm having the following
problems.

1. There is a continue button on the form and I set a breakpoint there.
However, if the form contains invalid data, the form is refreshed with
appropriate error messages and the Click event for the button does not get
called. (Note: several fields on the form have RequireFieldValidators
associated with them.) So how does the form know to even validate itself if
the code has not yet responded to the continue button being clicked?

2. I decided to try adding a new CustomValidator and associate it with
another control. I found that the ServerValidate event for the
CustomValidator does occur, but that setting args.IsValid = False seems to
have no effect.

3. 1. above seems to indicate that validation is being performed somehow on
the client side while my event handlers run on the server side. If this is
the case, then how can my CustomValidator event run in time to affect the
client-side validation?

Any help is appreciated!
 
K

Kelvin Tsang

Hi Jonathan,
2. I decided to try adding a new CustomValidator and associate it with
another control. I found that the ServerValidate event for the
CustomValidator does occur, but that setting args.IsValid = False seems to
have no effect.

I got a quick answer for your second question.
You have to put your control's code in the block:

if Page.IsValid
....
....
....
End if

Hope it helps.

-Kelvin
 
P

Peter Blum

You are correct that client-side validation may have run, preventing a post
back. Your custom validator is server-side only. So the page wasn't
submitted due to another validator on the page that offers client-side
validation. Once that validator accepts its entry, the post back will occur.
Then your button's Click event will run and automatically call
Page.Validate() for you. Next, your post back event handlers (like a button
Click event) fire. You test Page.IsValid before allowing your page to
"save".

Validators are designed to always run on the server side, even if the
client-side approved the data. That's because the user may have disabled
javascript or they are using a non-IE browser. (MS validators only support
DHTML browsers on client-side validation.)

FYI: My product, "Professional Validation And More"
(http://www.peterblum.com/vam/home.aspx), provides 22 validators, all which
support more browsers on the client-side including Netscape/Mozilla, Opera 7
and Safari. I built it because there are so many limitations in Microsoft's
validators that require custom coding and hacks. A list of those limitations
is at http://www.peterblum.com/vam/valmain.aspx.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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