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


W

wildman

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

Advertisements

M

Muhammad Naveed Yaseen

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.
 

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

Top