“Sys.WebForms.PageRequestManager'为空或不是对象 [英] 'Sys.WebForms.PageRequestManager' is null or not an object
问题描述
您好我有,我有以下的code aspx页
Hi I have an aspx page in which i have the following code
<asp:ScriptManager ID="scriptManager" runat="server" AsyncPostBackTimeout="500" EnablePageMethods="true">
</asp:ScriptManager>
<script type="text/javascript">
Sys.Application.add_init(BeginRequestHandler);
Sys.Application.add_init(EndRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
AsynProcessing('block', 'AlertDiv', 'ProcessingImage');
}
function EndRequestHandler(sender, args) {
AsynProcessing('none', 'AlertDiv', '');
}
function AsynProcessing(visstring, elem, img) {
var adiv = $get(elem);
adiv.style.display = visstring;
adiv.image = img;
}
但页面被抛出的javascrip错误为'Sys.WebForms.PageRequestManager'为空或不是一个对象。我已经放在ScriptManager的标签下方。我甚至攻占加入
But the page is throwing a javascrip error as 'Sys.WebForms.PageRequestManager' is null or not an object. I have placed the below the scriptmanager tag. I even ried adding
<xhtmlConformance mode="Transitional"/>
在web.config.But仍然得到同样的错误的部分。结果
任何帮助深表AP preciated。在此先感谢
in the section of web.config.But still getting the same error.
Any help is much appreciated. Thanks in advance
推荐答案
包装你处理这个code,以等待所有的脚本所必要的被装,叫 Sys.WebForms之前。 PageRequestManager
Wrap your handlers with this code, in order to wait for all nessesary scripts were loaded, before calling Sys.WebForms.PageRequestManager
Sys.Application.add_init(function(){ ... your code ....}
http://msdn.microsoft.com/en-us/library/ bb397532.aspx
编辑:错误在该行的原因<$c$c>Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler)$c$c>在脚本没有带被加载呢,所以如果你想处理一个异步回送的,你必须这样写:
The reason of error at this line Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler)
is scripts havn't been loaded yet, so if you want handling of an asynchronous postback, you have to write something like this:
Sys.Application.add_init(function(){
Sys.WebForms
.PageRequestManager
.getInstance()
.add_beginRequest(BeginRequestHandler)
});
这是什么意思用简单的英语?等到所有的脚本已经被加载(包括 Sys.WebForms
命名空间)和订阅事件的BeginRequest
您脚本块应该是这样的:
What does it mean in plain English? Wait until all scripts have been loaded (including Sys.WebForms
namespace) and subscribe to event beginRequest
You script block should be like this:
<script type="text/javascript">
Sys.Application.add_init(function () {
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
});
Sys.Application.add_init(function () {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
});
function BeginRequestHandler(sender, args) {
AsynProcessing('block', 'AlertDiv', 'ProcessingImage');
}
function EndRequestHandler(sender, args) {
AsynProcessing('none', 'AlertDiv', '');
}
function AsynProcessing(visstring, elem, img) {
var adiv = $get(elem);
adiv.style.display = visstring;
adiv.image = img;
}
</script>
这篇关于“Sys.WebForms.PageRequestManager'为空或不是对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!