Click here to Skip to main content
15,891,905 members
Articles / Web Development / HTML
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
14 Oct 2012CPOL 11.1K   7  
This post describes how to reference your Javascript files from a page that uses Routed URLs

Introduction

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

C#
<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:

C#
<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)


Written By
Founder Rebin Infotech
India India
A passionate developer with over 10 years of experience and building my software company code by code. Experience withMS Technologies like .Net | MVC | Xamarin | Sharepoint | MS Project Server and PhP along with open source CMS Systems like Wordpress/DotNetNuke etc.

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. #SOreadytohelp

Comments and Discussions

 
-- There are no messages in this forum --