65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Oct 14, 2012

CPOL
viewsIcon

11564

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:

<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>