ajax dopost,Ajax页面中,__doPostBack是如何判读何时发出异步请求的?

本文探讨了一种使用JavaScript进行异步回发的方法,特别是针对UpdatePanels。作者发现并分享了一个完全在JavaScript中实现异步回发的解决方案,绕过了通常需要特定控件触发异步回发的问题。通过修改PageRequestManager的内部数组,实现了类似__doPostBack的功能,但确保了异步执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Performing async postback from javascript

UpdatePanels are a great way to update portions of a webpage. They only have one "problem": they need a control to fire the async postback. When you are performing a postback from javascript using the following code:

__doPostBack( 'EventName' , 'EventArgs');

the execution will always be synchronous. You can work around this by using a hidden control and fire one of its events, but this is not always the most flexible solution. I debugged the framework javascript a little and found another way to do it, completely

in javascript. It's done by adding the eventtargetname into two arrays of the PageRequestManager. I have created a javascript function that handles this for me:

function doPostBackAsync( eventName, eventArgs )

{

var prm = Sys.WebForms.PageRequestManager.getInstance();

if ( !Array.contains( prm._asyncPostBackControlIDs, eventName) )

{

prm._asyncPostBackControlIDs.push(eventName);

}

if ( !Array.contains( prm._asyncPostBackControlClientIDs, eventName) )

{

prm._asyncPostBackControlClientIDs.push(eventName);

}

__doPostBack( eventName, eventArgs );

}

You can call it just like the original __doPostBack function.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值