您好我有一个aspx页面,其中我有以下代码
<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;
}
但由于'Sys.WebForms.PageRequestManager'为空或不是对象,该页面抛出了javascrip错误。我在scriptmanager标签下面放了。我甚至连了
<xhtmlConformance mode="Transitional"/>
在web.config.But部分仍然得到相同的错误 任何帮助深表感谢。提前致谢
答案 0 :(得分:5)
使用此代码包装处理程序,以便在调用Sys.WebForms.PageRequestManager
Sys.Application.add_init(function(){ ... your code ....}
http://msdn.microsoft.com/en-us/library/bb397532.aspx
编辑:此行Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler)
出错的原因是尚未加载的脚本,所以如果你想处理异步回发,你必须写这样的东西:
Sys.Application.add_init(function(){
Sys.WebForms
.PageRequestManager
.getInstance()
.add_beginRequest(BeginRequestHandler)
});
简单的英语是什么意思?等到所有脚本都已加载(包括Sys.WebForms
命名空间)并订阅事件beginRequest
你的脚本块应该是这样的:
<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>
答案 1 :(得分:2)
似乎您的JavaScript块在ASP.net Ajax加载之前正在执行,请尝试将其放在页面底部或<form>
标签之后......
答案 2 :(得分:0)
我也有这个问题。对我来说,这是由于Web服务器场和web.config中缺少machinekey条目。
<system.web>
<machineKey validationKey="D61B3C89CB33A2F1422FF158AFF7320E8DB8CB5CDA1742572A487D94018787EF42682B202B746511891C1BAF47F8D25C07F6C39A104696DB51F17C529AD3CABE"
decryptionKey="FBF50941F22D6A3B229EA593F24C41203DA6837F1122EF17" />