Master Page Image Display Problem and Solution in Asp.net
Master Page is creating problem when a page inside folder is trying to refer master page. The reason of problem is Master Page is using absolute image url, which changes when you try to refer same inside folder.
A simple solution to problem is to define relative path for images inside master page.
So if you have coded like following in your MasterPage File
<img src="Images/Logo.gif"/>
Than Replace it with,
<img src="<%= Page.ResolveUrl("~")%>Images/Logo.gif"/>
More about Asp.net Website Paths
10 comments:
This is a very interesting solution. I have always solved this problem by doing this:
<img src="~/images/logo.gif" runat="server" />
I think your solution may have less overhead.
I used the same solution as Luke said above but I still had issues and yours worked perfect.
Thanks!
I've put my head for 2 hours over two simple images 'plus.gif' and 'minus.gif'.... I wanted to toggle them using javascript. But in inside pages, this will not work.
I used this solution when assigning to javascript variables. Got it dear..... thanks a lot. :)
Great tip, thanks!
Thanks. Really helpful..
I was struggling with this for several hours. When I ran my website from Visual Studio, everything worked. When I put it on the IIS server, the images didn't display. I used your fix and all is well!
Thank you very much.
Did a miracle
Thank you very much for the solution
Worked like a wonder
i am new to asp.net i have create theme and using sideshow in jquery but the issue is when i build i am not able see the images .. example below
src="~images/img04.jpg" runat="server"
pls help..
I am using nested master pages. The code works on the main master page but it does not produce the images on the nested master page. Is there a way to make this work on the nested page or avoid the rewriting on the nested master page completely?
Do the url rewriting values need to be in the nested web.config file as well?
Hi DotNetGuts,
Thanks Worked like Charm!
I was getting cached url for image.
After using <%=Page.ResolveUrl("~")%>
it worked fine!
Thanks again.
Damo
Post a Comment