panel problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I have following code which receives Panel names from the database. It tells
me Object reference not set to an instance of an object. Why is that? Thanks
a lot for your help....
Chris

while (or.Read())

{

Panel pnl = new Panel();

pnl = (Panel)FindControl(or.GetString(0));

pnl.Visible = false;

}
 
Hi,

The most suspicious place seems to be this line:

pnl = (Panel)FindControl(or.GetString(0));

If FindControl returns null, you'll get the NullReferenceException.

P.S. This line:

Panel pnl = new Panel();

seems to be unnecessary at all.
 
Back
Top