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

  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. 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. Parthiv Joshi
    Replies:
    2
    Views:
    706
    Kalyan
    Jul 2, 2004
  2. Suresh Kojhani
    Replies:
    1
    Views:
    2,407
    Anushi
    Jul 29, 2004
  3. Replies:
    1
    Views:
    387
    Ken Cox [Microsoft MVP]
    Nov 5, 2004
  4. Fendi Baba
    Replies:
    0
    Views:
    310
    Fendi Baba
    May 13, 2007
  5. Replies:
    1
    Views:
    502
    Mark Rae [MVP]
    Sep 20, 2007
Loading...

Share This Page