Placing an image inside a Span (here : HtmlGenericControl ) programmatically
Want to have a process on it later via the FindControl
HtmlGenericControl spnMeta = new HtmlGenericControl("span")
{ ID = "spanMeta" };
//Literal litMeta = new Literal();
//litEdit.Text = "<span id=\"spanMeta\" class=\"meta\" runat=\"server\">" ;
Image imgCodeIcon = new Image()
{
ID="imgCodeIcon" ,
ImageUrl="../Images/Code-icon.gif" ,
Width = 15 , Height = 11
};
spnMeta.Controls.Add(imgCodeIcon);
// Shouldn't be important here ...
spnMeta.DataBinding +=new EventHandler(spnMeta_DataBinding);
// closing Span if Literal is used
Doing this way will have no effect :
spnMeta.Controls.Add(imgCodeIcon);
and image will be rendered outside of the span and next to it
Formerly I made the procedure via Literal as it’s commented out in the below code block
but that time seemed I can not access to it from server code
how could I achieve this ?
Here is some sample code to place an image into a placeholder via code:
ASPX
C#
This is the output: