views:

639

answers:

6

Hi all, I am trying to set up a masterpage that contains a javascript popup subroutine that can be used in multiple web pages. The popup already works in a single page environment. I now want to migrate it to a master page. Any ideas will be greatly appreciated. I already searched this site and tried a couple of the suggestions to no avail. W small working example would help. Thanks Bill

A: 

this is my current favourite, seems to be most robust and flexible. Simply include the js files in your master then create an isntance on your pages

Andrew Bullock
+1  A: 

Just take what you have in your single page and place it in the master page. It is really that simple. :) Then just replace the main body of the HTML in the master page with the content sections and you should be ready to go.

Nick Berardi
A: 

be sure to use the scriptmanager class to add the javascript

Chris Ballance
... if you're using AJAX :)
Slavo
A: 

Hi guys, thanks for the answers. One thing I did discover was that for some reason the derived page had to be in the same folder as the master page. Bill

A: 

Bill,

This is some pretty good info on this, recommended by scottgu!

http://www.edream.org/BlogArticle.aspx?RecordID=112

Anthony :-) www.codersbarn.com

IrishChieftain
+1  A: 

One thing I did discover 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 works for the master page, but not the internal pages themselves. One workaround would be using

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

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

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