ASP.NET: how to make onClientClick finish work before postback?

筅森魡賤 提交于 2019-12-24 00:27:18

问题


I have such a control:

<asp:Button ID="save_all_filt" runat="server" Text="All data for filtered subjects"
        OnClientClick="  a= saveAllFilt(); return true; "   onclick="save_all_filt_Click" />

saveAllFilt contains a JQuery ajax call. So what I see in log, I have simultaneous start of postback and saveAllFilt. Postback however "delays" and does nothing before Ajax call in saveAllFilt fninshes.

I wonder if there is a way to do like this: 1. onClientClick, system goes into saveAllFilt JS function and somehow waits(!) till Ajax function finishes in this or that way. 2. Only when it is finished, a real postback starts to happen.

I do realise that JQuery ajax call is event-driven and asynchronous. Just would like to block these postback actions till it finishes (AJAX call prepares data for retrieval that happens via server postback.)


回答1:


Set the async property of the jQuery AJAX config object to false:

$.ajax({
    /* ... */
    async : false
    /* ... */
})


来源:https://stackoverflow.com/questions/13310883/asp-net-how-to-make-onclientclick-finish-work-before-postback

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