Ross Barbish
Ross Barbish

Reputation: 679

asp:CustomValidator functionality

So I have this old asp .net 2.0 app and it has these asp:RequiredFieldValidator's and asp:CustomValidator's on some form controls.

When I turned off javascript in the web browser, I discovered the server/back-end validation was non-existent. After coding up a c# version of all the asp:Validator's for back-end validation I discovered that I could simply call [ValidatorID].IsValid to get whether or not a control's value was valid.

I guess my question is, since I turned off javascript, how does the app know if asp:CustomValidator's associated control is valid? Where and when is that javascript being run? It has got to be the server correct?

Also would the correct/suggested way to add back-end validation simply be to have if(validator1.IsValid && validator2.IsValid ...) { //isvalid } or is there a way I can see if the entire page is valid? Or a way to group validators so that I don't have to change the code-behind every time I add a validator?

Thanks - Ross

Upvotes: 0

Views: 65

Answers (2)

Jack Pettinger
Jack Pettinger

Reputation: 2765

Put a breakpoint on each one of your serverside validator functions, then call if(Page.IsValid) you will see that your code will go to each function in turn, and stop when it hits the first function that returns false.

Upvotes: 1

rs.
rs.

Reputation: 27467

On server side you can use if(Page.IsValid) to check if all validations validated succsfully, if client side validation is turned off, validation is done only on server side.

Refer to Page.IsValid MSDN documentation

Upvotes: 1

Related Questions