Page life cycle and Page.IsValid property

  • Thread starter Thread starter Gary Larimer
  • Start date Start date
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.
 
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.
 
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.
 
Back
Top