0

I have several asp validation controls on my page. I have an asp.net button on my page that saves everything on the page.

In the OnClick server-side event of the button should I always be wrapping it in a (if Page.IsValid) statement?

It seems like the validation still works regardless? Or is that only the client-side validation that is working?

Matthew Peterson
  • 325
  • 1
  • 4
  • 18
  • Could you show some parts of code? Why don't you call IsValid method of specific validator instead of general Page.IsValid? – ElConrado Aug 28 '15 at 22:20

2 Answers2

0

By default, validation will occur, fired by your button after Page_Load event.

Also, Page.IsValid make sense after calling Page.Validate(). Be aware that the latter occurs automatically in several scenarios.

Your question can be answered in more depth, but I won't go into more details as many others have already covered this subject. You can continue reading in this other SO question.

Community
  • 1
  • 1
zed
  • 2,298
  • 4
  • 27
  • 44
0

Page.Validate is called automatically however in some instances you are best calling the method in your own code. Calling the Page.Validate() method to trigger the server side validation.

You will then need to check the Page.IsValid property to find out if there are any validation errors or not. It is then up to you to decide if you want to page to continue processing or if you want to just return the page.

If you do not check the property and change the flow the event handling code will be executed.

You can find out if server side validation is happening yourself by disabling JavaScript in your browser and then submitting the form. This will by-pass the client side validation.

James
  • 983
  • 1
  • 9
  • 17