I have an ASP.NET link button that I need to add both text and an image to I thought I would be able to just add the image to the button using Controls.Add
but no dice.
Here is what I have so far:
foreach (var entity in metadata.Meta.Where(e => e.ReportableObject == true))
{
LinkButton lb = new LinkButton();
string iconpath = "~/images/search/" + entity.ClassName + ".png";
lb.CssClass = "entityIcon";
lb.Controls.Add(new Image { ImageUrl = iconpath , CssClass = "imgSize"});
lb.Text = entity.ClassName;
entityHolder.Controls.Add(lb);
}
When the control renders I see the text but I'm not even getting an image container rendered. I thought it might have been the path to the image but even when I tried to map to a image from an existing site using the full qualified path nothing would render.
Edit: For clarification there are no asp.net controls in the main page (link or image) this for loop is iterating a collection and creating the controls at runtime. The last line entityHolder
is a ASP.NET panel that the buttons are added to.
Can someone help me understand what I am doing wrong if this is even possible. I have to use a LinkButton
and not an ImageButton
as I need to render both text and image.
Cheers