开发者

Add Script Reference (JavaScript) to Script Manager on Microsoft AJAX Partial Postback

I am trying to add a script reference to the script manager in the event of a Microsoft AJAX Partial Postback, ie a user clicks on a link in an Update Panel.

ScriptManager.RegisterClientScriptInclude(Page, Page.GetType(), "UniqueName",
                                          Page.ResolveUrl(scriptPath));

Doesn't work and either does

ScriptReference script = new ScriptReference(scriptPath);
MyScriptManager.Scripts.Add(script);

From what I have read on the net, RegisterClientScriptInclude should work even in a partial postback. http://www.codeproject.com/KB/ajax/addingCssJsAjaxPartialPos.aspx

开发者_Go百科

Can anyone give any ideas why these don't work, or another way to do it?

EDIT: Additional information.

I am working with a very large legacy code base that has the forms and script manager in each page rather than in the master page. I would like to place the code into a class and use the following call to add the javascript effect.

ClientSideScripts.BackgroundColourFade(Page, ScriptManager, Control);

The reasons I want to include the script in the method call is

  1. Consumes of the method don't have to remember to include the script
  2. Changing the script used only requires a change in one place
  3. Only include the javascript when needed to keep the load time of the page down


Have a look at this SO-Question because it answers your question:

  • ScriptManager.RegisterClientScriptInclude does not work in UpdatePanel
function dynamic() {
  alert('dynamic');
  $('#divDyn').text('Dynamic!');
}
// notify that the script has been loaded <-- new!
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜