Thursday, November 4, 2010

JS file from a master page

Credit to

Finally a method that works ...

In the master page Page_Load event

protected void Page_Load(object sender, EventArgs e)
HtmlGenericControl myJs = new HtmlGenericControl();
myJs.TagName = "script";
myJs.Attributes.Add("type", "text/javascript");
myJs.Attributes.Add("language", "javascript"); //don't need it usually but for cross browser.
myJs.Attributes.Add("src", ResolveUrl("../Script/fileIO.js"));


Now you can reference its functions in the master page markup and in the content page markup.

No comments: