ItemCreated FindControl problem c#

G

Guest

All I need to do is set the border property of an image control to border=0.
I want to do this at runtime for the first image on the page in a datalist.
In the ItemCreated event I'm trying to use FindControl to set a reference to
the img control so I can change the attribute. But when I run the code below
I get the error: "Object reference not set to an instance of an object." I
assume its not finding the control and returning null? Anyway, you can see
what I'm trying to do, can anyone tell me how to get it to work? (code below)

******* code *******
public void main_ItemCreated(Object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
HtmlImage imgPatron = new HtmlImage();
imgPatron = (HtmlImage)e.Item.FindControl(Request.Form["patron"]);
if(imgPatron!=null)
{
image_count();
if(i_count == 1)
{
imgPatron.Border = 0;
}
}

}

************

Thanks for any help!
 
E

Eliyahu Goldin

Wrong event. I recommend using PreRender event since the page is fully built
at that stage. You can use ItemDataBound if you wish, but PreRender is
easier.

Eliyahu
 
G

Guest

What is exactly the "Request.Form["patron"]"?

I think you should write:


.....FindControl(ID/name of the server side control);


Hope this help
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top