Prevent Full Postback from __doPostBack

笑着哭i 提交于 2019-12-06 09:39:40

Define the function below and replace your __doPostBack calls with doPostBackAsync(controlId, null).

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);
}

The controlId should be the id of the button to generate async postback else full postback occurs in the page. For that you can use the clientidmode as static e.g

<asp:Button ID="button1" runat="server"  ClientIDMode="Static"/>

   //then you can use below code
   _doPostBack('button1', '');//clientidmode forces buttonid = id given by us

Check its correct?

If so then you can get the async postback instead of a full page postback.

This helped me. Thanks @Tim for his comment.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!