(diclaimer: I didn't test this code... it's a guess).
You may use a control adapter to hook the page rendering, in order to inject a script reference to your javascript file.
Look at this page to show the source code of a working solution. The advantage of this solution, is that it use an HttpModule to register the script. Thus, you only have to modify the web.config of each projects, and not change the base class of all pages.
Adapted to your situation, this should looks like:
public class ScriptManagerAddModule : IHttpModule
{
public void IHttpModule.Dispose() { }
// This is where you can indicate what events in the request processing lifecycle you want to intercept
public void IHttpModule.Init(System.Web.HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(HttpApplication_PreRequestHandlerExecute);
}
void HttpApplication_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication httpApplication = sender as HttpApplication;
if (httpApplication != null)
{
Page page = httpApplication.Context.CurrentHandler as Page;
if (page != null)
{
// When standard ASP.NET Pages are being used to handle the request then intercept the
// PreInit phase of the page's lifecycle since this is where we should dynamically create controls
page.PreInit += new EventHandler(Page_PreInit);
}
}
}
void Page_PreInit(object sender, EventArgs e)
{
Page page = sender as Page;
if (page != null)
{
// ScriptManagers must be in forms -- look for forms
foreach (Control control in page.Controls)
{
HtmlForm htmlForm = control as HtmlForm;
if (htmlForm != null)
{
// Look for an existing ScriptManager or a ScriptManagerProxy
bool foundScriptManager = false;
foreach (Control htmlFormChild in htmlForm.Controls)
{
if (htmlFormChild is ScriptManager || htmlFormChild is ScriptManagerProxy)
{
foundScriptManager = true;
break;
}
}
// If we didn't find a script manager or a script manager proxy then add one
if (!foundScriptManager)
{
htmlForm.Controls.Add(new ScriptManager());
}
}
}
// Addition to the original code
ScriptManager.GetCurrent().RegisterClientScriptInclude(page, typeof(ScriptManagerAddModule), "myjavascript", "jsSource.js");
// End of addition to the original code
}
}
This code will both ensure the presence of a ScriptManager control, and register a custom javascript file (see my addition at the bottom of the code).
Then, in all web.config files, register the module:
<httpModules>
<add name="ScriptManagerAddModule" type="YourLibrary.ScriptManagerAddModule"/>
</httpModules>
Please note that you have to put the module code in a class library, referenced by all other projects (or at least having the dll in all bin folders, or GAC, or any location that .net use to look at dll).
MasterPages?