Page life cycle and Page.IsValid property

G

Gary Larimer

I an asp.net web page with a simple form and a Submit button. Form entries
are validated client side, but as a back up I would also like to validate
server side, but not sure where to do it code.

Can the Page.IsValid property be checked in the following code:

protected void Page_Load()
{
if(IsPostBack)
{
//can IsValid be checked here on PostBack
if(IsValdi) { //respond here if not valid }
}
}

Or do I have to check IsValid in the button click handler?

Looked at page life cycles at msdn, but am not certain when the IsValid
property can be processed in code.

Thanks for any comments.
 
Y

Yankee Imperialist Dog

you can call a Page.Validate() at various point in a page if you like to
force validation. The reason i note this is that using

if (Page.IsValid)
{
}
will throw an error if referenced when a validate() has not been fired.

I don't think this is a direct answer to your question, but I hope this helps.
 
G

Gary Larimer

Thanks for the reply. I did try the code as shown in my post, and it did
throw an error as you noted. So, put if(IsValid){ } in button click
procedure where it works fine.
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top