Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

image not displaying when runat="server" is set

Tags:

c#

asp.net

i have an image as such:

<img src="../pics/img.gif" runat="server" id="imgID" alt="Close" />

the image is not displayed unless i removed the runat="server".
is there any reason for this behavior?

like image 231
lila Avatar asked Apr 25 '26 02:04

lila


2 Answers

It must be calling Control.ResolveClientUrl and ending up with the wrong path. If you look at the HTML source you'll probably figure out what's going wrong.

Try

<img src="~/pics/img.gif" runat="server" id="imgID" alt="Close" />

to set the path relative to the project root.

like image 173
Martin Smith Avatar answered Apr 27 '26 14:04

Martin Smith


try

<asp:image ImageUrl="~/pics/img.gif" runat="server" ID="imgID" AlternateText="Close" />
like image 37
Daniel Dyson Avatar answered Apr 27 '26 16:04

Daniel Dyson