Prerender and Gridview - Object reference not set to an instance ofan object.

Discussion in 'ASP .Net' started by wildman@noclient.net, Mar 3, 2008.

  1. Guest

    In the Page_load my code check to see if session variable is set, if
    it is, it calls some subroutines that loads some grids and binds them.

    In my prerender, when the grids row is in update mode, and the key = 0
    (meaning I'm inserting) I'd like to set a date field to current date.

    the above logic works great in another page I have where I am not
    checking for session information in the page load, but in th is code
    results in the error.

    Object reference not set to an instance of an object.

    dumb question, in my prerender, how can check if my gridview has been
    instantiated to avoid this error. I suspect this the problem. I guess
    I could just wrap the whole thing in a try catch.

    Actually, I just tried that and this does not seem to correct the
    problem, I don't get the error, but I am unable to set the column.

    Thanks for any help or information.
     
    , Mar 3, 2008
    #1
    1. Advertisements

  2. Re: Prerender and Gridview - Object reference not set to an instanceof an object.

    On Mar 3, 12:18 pm, wrote:
    > In the Page_load my code check to see if session variable is set, if
    > it is, it calls some subroutines that loads some grids and binds them.
    >
    > In my prerender, when the grids row is in update mode, and the key = 0
    > (meaning I'm inserting) I'd like to set a date field to current date.
    >
    > the above logic works great in another page I have where I am not
    > checking for session information in the page load, but in th is code
    > results in the error.
    >
    > Object reference not set to an instance of an object.
    >
    > dumb question, in my prerender, how can check if my gridview has been
    > instantiated to avoid this error. I suspect this the problem. I guess
    > I could just wrap the whole thing in a try catch.
    >
    > Actually, I just tried that and this does not seem to correct the
    > problem, I don't get the error, but I am unable to set the column.
    >
    > Thanks for any help or information.


    1) Usually it is better to do this kind of thing in DataBound event of
    the control (here GridView).

    2) It may be better to check the variable of concern for null (i.e. if
    (someVar == null)) rather than forcing it go silent in try catch
    block.
     
    Muhammad Naveed Yaseen, Mar 3, 2008
    #2
    1. Advertisements

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. Parthiv Joshi
    Replies:
    2
    Views:
    919
    Kalyan
    Jul 2, 2004
  2. Suresh Kojhani
    Replies:
    1
    Views:
    2,661
    Anushi
    Jul 29, 2004
  3. Chris Fink
    Replies:
    2
    Views:
    4,315
    David Waz...
    Jul 3, 2003
  4. yysiow
    Replies:
    1
    Views:
    574
    Kevin Spencer
    Jul 12, 2003
  5. Tim
    Replies:
    1
    Views:
    603
    Bill Priess
    Jul 17, 2003
  6. Replies:
    1
    Views:
    452
    Ken Cox [Microsoft MVP]
    Nov 5, 2004
  7. Fendi Baba
    Replies:
    0
    Views:
    384
    Fendi Baba
    May 13, 2007
  8. Replies:
    1
    Views:
    704
    Mark Rae [MVP]
    Sep 20, 2007
Loading...