Relative Path in master page for img tag

…衆ロ難τιáo~ 提交于 2019-12-10 14:40:16

问题


I have a tag in a master page. I use this master page in many folders. So the src path of the tag should be different for each folder. Here is my code :

<img src="images/1.gif" />

and I have a folder named "images" and a folder named "Users". Master Page is in the root, but I use it in Users folder.

How can I set a dynamic address for src?


回答1:


The easiest way would be to use an asp:Image tag. You need to add runat="server" in order to use ~ syntax to resolve your URLs.

<asp:Image ID="myImage" runat="server" ImageUrl="~/images/1.gif" />



回答2:


Just use <img runat="server" src="~/images/1.gif" />. This is documented here.



来源:https://stackoverflow.com/questions/1506408/relative-path-in-master-page-for-img-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!