RegisterClientScript code后的部分后不工作回来 [英] RegisterClientScriptCode not working after a partial post back

查看:144
本文介绍了RegisterClientScript code后的部分后不工作回来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code的以下行是在SharePoint网站的用户控件。

The following lines of code are in a user control in a SharePoint website.

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "jquery144", "<script type=\"text/javascript\" src=\"/_layouts/Unicre.Web.RUOnline.Controlos/Scripts/jquery-1.4.4.min.js\"></script>", false);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "javascriptgeral", "<script type=\"text/javascript\" src=\"/_layouts/Unicre.Web.RUOnline.Controlos/Scripts/javascript.js\"></script>", false);

为什么它不工作?我也找不到在响应生成的HTML相应的脚本标记。

Why doesn't it work? I also can't find the respective script tags in the HTML generated in the response.

问题有一个更新面板做。在局部回传后,JavaScript的停止工作。如果不是上述code工作?

The problem has to do with an update panel. After the partial postback, the Javascript stops working. Shouldn't it work with the above code?

(Ⅰ也试过RegisterClientScriptInclude方法,但具有相同的结果。)

(I also tried the RegisterClientScriptInclude method but with the same result.)

推荐答案

这是不会在局部回传工作。您需要注册在的Page_Load 的脚本。在用户控制,连接到Load事件,并从该处理程序调用ScriptManager.RegisterClientScriptBlock()。

This isn't going to work on a partial postback. You need to register the scripts on Page_Load. In the user control, attach to the Load event and call ScriptManager.RegisterClientScriptBlock() from that handler.

在局部回传后,JavaScript的停止工作。

After the partial postback, the Javascript stops working

一个UpdatePanel部分回发是在UpdatePanel &LT的DOM更新; DIV&GT; 内容。这意味着previous内容会丢失,所以内联脚本的状态,包含内&LT; D​​IV&GT; 失去其状态

An UpdatePanel partial postback is DOM update of the UpdatePanel <div> contents. This means the previous contents are lost, so the state of inline script contained within that <div> loses its state.

请参阅这里了解更多信息:

通过的UpdatePanel在 innerHTML的DOM属性确实在客户机上的工作。的Δ被从服务器检索,发现自己在现有的DOM中,内容部署,然后分配经由innerHTML的新内容。 ...但是内嵌脚本不会以这种方式工作。设置DOM元素,HTML,其中包含一个脚本块的innerHTML不会导致脚本来执行。

UpdatePanel does its work on the client through the innerHTML DOM property. A delta is retrieved from the server, finds itself in the existing DOM, disposes of the contents, and then assigns the new content via innerHTML. ... But inline script doesn't work this way. Setting the innerHTML of a DOM element to HTML which contains a script block does not cause that script to execute.

同样,调用ScriptManager.RegisterClientScriptBlock()上的一个UpdatePanel更新不会像一个页面加载。你可以添加&LT;脚本方式&gt; 直接元素UpdatePanel的内容,但它不会执行

Likewise, calling ScriptManager.RegisterClientScriptBlock() on an UpdatePanel update is not going to act like a page load. You could add the <script> elements directly to the UpdatePanel contents, but it won't execute.

更新

您可以通过<一个部分回发后调用JavaScript code href=\"http://zeemalik.word$p$pss.com/2007/11/27/how-to-call-client-side-javascript-function-after-an-updatepanel-asychronous-ajax-request-is-over/\"相对=nofollow>添加endRequest处理程序的PageRequestManager :

<script>
function load() {
   //register the handler
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}
//this handler will execute after a partial postback
function EndRequestHandler(){
   //...arbitrary code...
}
window.onload = load; 
</script>

这篇关于RegisterClientScript code后的部分后不工作回来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆