Javascript in masterpages ASP.NET 2.0

I am trying to create a master page that contains a javascript popup routine that can be used across multiple web pages. The popup is already working in a single page environment. Now I want to move it to the main page. Any ideas would be much appreciated. I've already searched this site and tried a couple of suggestions to no avail. A small working example will help. thanks bill

0


source to share


4 answers


Just take what you have on one page and put it on your home page. It's really that simple. :) Then just replace the main HTML text on the home page with content sections and you should be ready to go.



+1


source


One thing I found was that for some reason the derived page had to be in the same folder as the master page.

Most likely caused by the master page referencing a subdirectory that runs on the master page, but not on the inner pages themselves. One way would be to use

ScriptManager.RegisterClientScriptInclude(string Key, string URL)
like so:
ScriptManager.RegisterClientScriptInclude("uniqueIdentifier", "~/javascript/myjs.js");

      



Alternatively, you can insert the file as a resource and use

ScriptManager.RegisterClientScriptResource(Page, Type, Key);
like so:
ScriptManager.RegisterClientScriptResource(this.Page, typeOf(Page), "resourceKey");

      

+1


source


this one is my current favorite, seems to be the most reliable and flexible. Just include js files in your master, then create isntance in your pages.

0


source


be sure to use the scriptmanager class to add javascript

0


source







All Articles