Search 
DailyCoding > Web

The Script tag runat="server" Problem Solution Using ResolveUrl

Solution to the script tag runat="server" problem
Author admin on Jul 21, 2008 2 Comments
Rate it    (Rated 1 by 1 people)
815 Views

This might be an easy trick, but I ran into this issue a while ago; we can not specify the runat="server" attribute on a JavaScript file link as we do for images and style sheet.

<link id="mainSheet" runat="server" href="~/Images/styles.css" 
rel="stylesheet" type="text/css" />

By using runat=server the href of the link will automatically be resolved by the asp.net in we have placed ~/ in the path. This gives us advantages when we are linking this into a control and the control could be used by other pages places at a different directory level.

Same problem arise with using linked JavaScript. But this cannot be solved by using runat=server tag. Here is an alternative way to overcome this problem.

<script language="javascript" src="<%=ResolveUrl("~/App_Themes/MainTheme/jquery.js")%>" type="text/javascript"></script>
ASP.NET | Web

Discussion

Stefan On Oct 1, 2008 05:41 AM
Where is the solution??

Daily Coder On Oct 1, 2008 11:10 PM
@Stefan, sorry there was some problem with html code. It is corrected now. Thanks for reporting :).

Leave a Comment

Name
Email Address
Web Site
© Copyright 2008 Daily Coding • All rights reserved