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