external js file with masterpage

  • Thread starter Thread starter Stan SR
  • Start date Start date
S

Stan SR

Hi,

I use a masterpage for all my project.
For some pages I have some external javascript file that I would like to
include.
How can I do this action from the content pages ?

Stan
 
From individual pages, this is simple. Just link to the JavaScript. From the
master page, it is more difficult, as the JavaScript linking does not
respect the ResolveClientUrl() for some reason. Either that, or I have not
found the magic.

Put the links in teh pages you need, or create a page object that has the
link and inherit from it.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think Outside the Box!
*************************************************
 
Stan SR napsal(a):
Hi,

I use a masterpage for all my project.
For some pages I have some external javascript file that I would like to
include.
How can I do this action from the content pages ?

Stan
Try following code(in masterpage's OnLoad)

protected string m_sScript = "MasterPageRoot/MasterPageScript.js";

.....
string sPrefix = string.Empty;
if (Request.AppRelativeCurrentExecutionFilePath.IndexOf("inner-folder")
sPrefix = "../";

this.DataBind();

.... and in masterpage
<script src="<%#m_sScript%>" type="text/javascript">

Pavel
 
Back
Top