Page life cycle and Page.IsValid property

Discussion in 'ASP .Net' started by Gary Larimer, Jul 30, 2008.

  1. Gary Larimer

    Gary Larimer Guest

    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.
    --
    Gary Larimer
    Gary Larimer, Jul 30, 2008
    #1
    1. Advertising

  2. 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.




    --
    Share The Knowledge. I need all the help I can get and so do you!


    "Gary Larimer" wrote:

    > 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.
    > --
    > Gary Larimer
    Yankee Imperialist Dog, Jul 30, 2008
    #2
    1. Advertising

  3. Gary Larimer

    Gary Larimer Guest

    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.
    --
    Gary Larimer


    "Yankee Imperialist Dog" wrote:

    > 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.
    >
    >
    >
    >
    > --
    > Share The Knowledge. I need all the help I can get and so do you!
    >
    >
    > "Gary Larimer" wrote:
    >
    > > 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.
    > > --
    > > Gary Larimer
    Gary Larimer, Aug 1, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Rilling
    Replies:
    5
    Views:
    355
    Peter Rilling
    Mar 9, 2005
  2. Guest
    Replies:
    3
    Views:
    2,784
    Bruce Barker
    Sep 6, 2005
  3. Fred
    Replies:
    5
    Views:
    6,244
    Karl Seguin [MVP]
    Jan 23, 2006
  4. clintonG

    App_Code and the Page Life Cycle

    clintonG, Jul 15, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    520
    clintonG
    Jul 15, 2006
  5. lander
    Replies:
    5
    Views:
    2,527
    Mark Rae [MVP]
    Mar 3, 2008
Loading...

Share This Page