Reputation: 175
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 + '"/>";
Upvotes: 0
Views: 1659
Reputation: 9129
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;
Upvotes: 1