Using Master Pages and ResolveUrl() in ASP.NET

16 June 2008 15:47 by mustafaozcan

MasterPages came with ASP.NET 2.0 and it's very useful. If you are using master pages, JavaScript files, images, links and sub folders in own projects. This article is very useful for you.

For example you insert image in your master page and create an aspx file in subfolder.

In master page : <img src="Images/mustafaozcanblog.png" alt="Mustafa ÖZCAN's Blog" />

Sample.aspx file is in samples folder and it is use master page in root folder. Added images cannot be displayed in rendered sample.aspx page because images folder in root folder but samples.aspx page search it in samples directory.

So you have two ways solution for this problem:

1st Way: You must change this line for added image  : 


<img src="~/Images/mustafaozcanblog.png" alt="Mustafa ÖZCAN's Blog" runat="server"/>


2nd Way: You must change this line for added image :


 <img src='<%=ResolveUrl("~/Images/mustafaozcanblog.png")%>' alt="Mustafa ÖZCAN's Blog" />


You can use 2nd Way to added JavaScript files and other external content in master page file.



2225 times displayed

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET | Tips & Tricks

Add comment (Your comment will be displayed when approved)


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.0.0

About the author

Mustafa OZCAN Mustafa ÖZCAN
Software Developer

E-mail me Send mail

Recent comments

Comment RSS

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

© Copyright 2008

Added Files

File Hit
jquery-1.2.6-intellisense.js 2276
   

Online

Online Visitors : 5