referencing a control in a webform that uses master page

M

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top