ASP.NET:如何使onClientClick在回发之前完成工作? [英] ASP.NET: how to make onClientClick finish work before postback?
问题描述
我有这样的控制权
<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包含一个JQuery ajax调用.因此,我在日志中看到的是,我同时开始回发和saveAllFilt.但是,回发延迟"并且在saveAllFilt形式的Ajax调用之前不执行任何操作.
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.
我想知道是否有办法做到这一点: 1.在onClientClick上,系统进入saveAllFilt JS函数,然后以某种方式等待(!)直到Ajax函数完成. 2.只有完成后,才会发生真正的回发.
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.
我确实意识到JQuery ajax调用是事件驱动和异步的.只是想阻止这些回发操作直到完成(AJAX调用为通过服务器回发进行的检索准备数据).
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.)
推荐答案
设置 async
属性到false
的jQuery AJAX配置对象:
Set the async
property of the jQuery AJAX config object to false
:
$.ajax({
/* ... */
async : false
/* ... */
})
这篇关于ASP.NET:如何使onClientClick在回发之前完成工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!