Page.Validate

G

Guest

When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be invoked. I am probably wrong about that.

If I am suppose to use this function, the edits seemed to be invoked even when you have pressed the cancel and the "CausesValidation" is set to false. Is there a way to get around this (might just be an acedemic question if I should not be running Page.Validate() if the first place.

Thanks in advance for your assistance!!
 
B

bruce barker

if the browser is not ie, or javascript is disabled, all validation is
serverside. for serverside validation to run you must call Page.Validate or
Page.IsValid.

-- bruce (sqlwork.com)


Jim Heavey said:
When should you use the Page.Validate() method? I thought you would use
this method if you have some Server side validation (CustomControl's) you
wanted to use and this would cause them to be invoked. I am probably wrong
about that.
If I am suppose to use this function, the edits seemed to be invoked even
when you have pressed the cancel and the "CausesValidation" is set to false.
Is there a way to get around this (might just be an acedemic question if I
should not be running Page.Validate() if the first place.
 
G

Greg Burns

Page.Validate is not the same as Page.IsValid (obviously)

I've never found a reason to call Page.Validate myself (not that there
probably aren't some good ones). Here is a contrived example from the help
files.

Sub Page_Load
If Not IsPostBack
' Validate initially to force the asterisks
' to appear before the first roundtrip.
Validate()
End If
End Sub

I always do a check of Page.IsValid first thing in my button click events.

If Not Page.IsValid Then Return

Like Bruce said, if (for whatever reason) your client-side javascript didn't
prevent the page from posting in the first place then the server validate
events will run. You use Page.IsValid to make sure that the server
validation didn't catch anything.

HTH,
Greg
 
G

Greg Burns

Here is a good reason (submitted by DujHoD in prior post) to call
Page.Validate that I'd forgotten.

----------------------
I believe you can use the IsValid property of the validator itself to
check this.

http://msdn.microsoft.com/library/e...WebControlsBaseValidatorClassIsValidTopic.asp

Note that validation happens AFTER the Page_Load event, so if you get
this property in the Page_Load event, it will always return True,
since the control has not yet been validated. If you must check
validity in the Page_Load event, you can manually call the
Page.Validate method (or just call the Validate method of the
validator you want to check on).

http://msdn.microsoft.com/library/en-us/dnaspp/html/aspplusvalid.asp
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top