var image = "image1.jpg"; //suppose label.Text = "<asp:Image ID='Image2' src..." /> var image = "image1.jpg"; //suppose label.Text = "<asp:Image ID='Image2' src..." /> var image = "image1.jpg"; //suppose label.Text = "<asp:Image ID='Image2' src..."/>

how to put a variable in the image source in C# like we do in php ">

var image = "image1.jpg"; //suppose
label.Text = "<asp:Image ID='Image2' src='images/" + image + '"/>";

1 Answers

2
slfan On

It is not exactly clear what you want to do: <asp:Image /> is a server tag which you should place on your webForm.aspx. If you assign the tag to the label, it will be HTML encoded and not display the image

You could do the following on the .aspx page:

<asp:Image id="Image2" ImageUrl="images/<%= image %>" runat="server" />

Or set the image url in the code behind:

Image2.ImageUrl = "images/" + image;