Home All Groups Group Topic Archive Search About

referencing a control in a webform that uses master page

Author
26 Jan 2007 1:54 PM
mike
I have the following in a page_load event

  Image img = new Image();
  img = (Image)
FormView1.Controls[0].NamingContainer.FindControl("Image1");
  if (img.ImageUrl.Length < 20)
     img.ImageUrl = "images/unavailable.jpg";

The page uses a master page with ContentPlaceHolder1 in which I have
placed FormView1.

FormView1.Controls[0].NamingContainer.UniqueID returns
ctl00$ContentPlaceHolder1.$FormView1

this works fine until placed on the production server at which point it
barfs with:

Object reference not set to an instance of an object.

what would cause this?  Maybe the code being in the page_load event?
Perhaps it should be moved to another event?  I did try the same code
in the Formview1.PreRender event as well.....same results

Thanks,

Mike