Using Master Pages and ResolveUrl() in ASP.NET

 - 16 June 2008 08:47 Admin

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.


Paylaş

Tags:

ASP.NET | Tips & Tricks

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


About the author

Mustafa OZCAN Mustafa ÖZCAN
Software Developer

E-mail me Send mail

PayPal Donate


Recent comments

Comment RSS

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

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 5171
   

Online : 6