I've been attempting to insert a script reference into the script manager during a Microsoft AJAX Partial Postback, specifically when a user clicks on a link in an Update Panel.
ScriptManager.RegisterClientScriptInclude(Page, Page.GetType(), "UniqueName",
Page.ResolveUrl(scriptPath));
Unfortunately, this method doesn't seem to work, and neither does
ScriptReference script = new ScriptReference(scriptPath);
MyScriptManager.Scripts.Add(script);
Although I have researched online where it is suggested that RegisterClientScriptInclude should function even during a partial postback. http://www.codeproject.com/KB/ajax/addingCssJsAjaxPartialPos.aspx
Does anyone have any insights as to why these approaches are failing, or perhaps know of another way to accomplish this?
EDIT: Additional details.
I am dealing with a large legacy code base where each page has its own forms and script manager instead of being placed within a master page. I am aiming to consolidate the code into a class and make use of the following method call to implement the JavaScript effect.
ClientSideScripts.BackgroundColourFade(Page, ScriptManager, Control);
The rationale for including the script within the method call is as follows:
- Users of the method won't need to remember to include the script separately
- Changing the script used only necessitates a modification in one location
- Including the JavaScript only when required helps maintain optimal page load times