Click here to Skip to main content
Click here to Skip to main content

How to allow correct JavaScript references with pages using a Routed URL

By , 14 Oct 2012
 

Introduction

Today, every application uses JavaScript. For referencing JavaScript in our .NET application in ASPX pages, we use the following syntax:

<script src="jquery.min.js" type="text/javascript" charset="utf-8"></script>  

When working with Routed URLs, the above syntax fails to download the referenced JavaScript files.

Using the code

To resolve this issue, the scripts should be re-written as below:

<script src="<%=ResolveUrl("~/jquery.min.js") %>" type="text/javascript" charset="utf-8"></script> 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Nitesh Luharuka
Technical Lead Independent IT Professional, Consultant
India India
Member
An Independent IT Professional and Consultant on MS Technologies like .Net | MVC | Silverlight | Sharepoint | MS Project Server along with open source CMS Systems like DotNetNuke etc.
 
I am an enthusiastic technocrat who love to debug problems and solve them. I love writing articles on my website in my spare time. Please visit my Website for more details and subscribe to get technology related tips/tricks.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 14 Oct 2012
Article Copyright 2012 by Nitesh Luharuka
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid