Saturday, March 24, 2012

Okay, how do I get the "name" of the image?...

The following code is supposed to create a rollover image for an ImageButton WebControl that is inside of a Repeater WebControl. The only problem is that it won't work because I don't know how to get the "name" of the image that ASP.NET gives the image at runtime.. Here is the code...


protected void rptrNewReleases_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
ImageButton imgbtnImageButton = (ImageButton)e.Item.FindControl("imgAddToCart");

// (e) needs to be replaced with the "name" this image is given at runtime, but how?
imgbtnImageButton.Attributes.Add("onmouseover", "MM_swapImage('" + (e) + "','','button_addtocart_on.jpg',1)");
imgbtnImageButton.Attributes.Add("onmouseout", "MM_swapImgRestore ()");
}

The name of the image in the first Item is something like name="rptrRepeateRegion:ctl0:imgAddToCartButton"

In the second (Alternating) Item it is name="rptrRepeateRegion:ctl1:imgAddToCartButton"

and so forth...

Is there any function to get this name that ASP.NET creates?

for example: e.Item.ItemName (something like this...)

Thanks (hope this makes sense)Have you tried imgbtnImageButton.ID?

0 comments:

Post a Comment