I have a form with gridview that is bound to a complex stored procedure (financial data). This query takes about 3 minutes to run and load the gridview. The users get impatient and click "Search" repeatedly, which just makes things worse.
我有一个gridview的表单绑定到一个复杂的存储过程(财务数据)。此查询大约需要3分钟才能运行并加载gridview。用户不耐烦并反复点击“搜索”,这只会让事情变得更糟。
As an interim solution, I'd like to show a progress bar, and I found a solution using the ASP.NET AJAX ModalPopupExtender.
作为一个临时解决方案,我想展示一个进度条,我找到了一个使用ASP.NET AJAX ModalPopupExtender的解决方案。
This is the code I have for adding the extender to the page:
这是我将扩展器添加到页面的代码:
<ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="Button1"
PopupControlID="pnlPopup" BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlPopup" runat="server" CssClass="updateProgress" style="display: none">
<div align="center" style="margin-top: 13px;">
<img src="../images/progress.gif" alt="Progress" />
<span class="updateProgressMessage">Loading ...</span>
</div>
</asp:Panel>
This is the very simple code for the button's click event:
这是按钮单击事件的非常简单的代码:
protected void Button1_Click(object sender, EventArgs e)
{
gvInvoice.DataBind();
}
The problem is, when I click the Search button, the modal dialog pops up but the Databind() method never gets called. I tried using mdlPopup.Show()
but that doesn't show the dialog and instead just runs the Databind()
.
问题是,当我单击“搜索”按钮时,会弹出模式对话框,但永远不会调用Databind()方法。我尝试使用mdlPopup.Show(),但是没有显示对话框而只是运行Databind()。
What am I missing? How do I ensure that the modal dialog appears, the databind runs, and the modal dialog subsequently disappears?
我错过了什么?如何确保出现模态对话框,数据绑定运行,模式对话框随后消失?
2 个解决方案
#1
It looks like you try to show progress panel (modal popup) for full page post-back? mdlPopup.Show() would work if the search action is done within updatepanel
看起来你试图显示整页回发的进度面板(模态弹出窗口)?如果搜索操作在updatepanel中完成,mdlPopup.Show()将起作用
In your scenario, try this instead - Step 1, set the TargetControlID of the modalpopupextender to a dummy hidden control - Step 2, added javascript call that shows the modalpopup $find('mdlPopup').show(); before the post-back call of search button's onclient event (just like adding a validation before post-back)
在你的场景中,试试这个 - 步骤1,将modalpopupextender的TargetControlID设置为虚拟隐藏控件 - 步骤2,添加javascript调用,显示modalpopup $ find('mdlPopup')。show();在搜索按钮的onclient事件的回拨之前(就像在回发之前添加验证一样)
James
#2
I think what you need to do here is separate the showing of the dialog and the binding from the fetching of the data.
我认为你需要做的是将对话框的显示和数据提取的绑定分开。
I would probably solve the problem using an approach like this:
我可能会使用这样的方法解决问题:
- Show Dialog and spin thread to go fetch the data. (the thread would put the data in the session cache, or a customised cache on a database.)
- Have the client poll the server for if the data is available (probably using AJAX calls to static page methods).
- When the data is available, hide the dialog and do the databind.
显示Dialog和旋转线程以获取数据。 (该线程会将数据放入会话缓存中,或者将数据库中的自定义缓存放入。)
让客户端轮询服务器以获取数据是否可用(可能使用对静态页面方法的AJAX调用)。
当数据可用时,隐藏对话框并执行数据绑定。
You can put additional checks/conditions around when the thread is started so that you don't start too many threads if the user presses search a number of times. I.e. if they haven't changed the search criteria then don't start a new search, but just continue polling.
您可以在线程启动时添加其他检查/条件,以便在用户按下搜索次数时不会启动太多线程。即如果他们没有更改搜索条件,则不要开始新搜索,只是继续轮询。
#1
It looks like you try to show progress panel (modal popup) for full page post-back? mdlPopup.Show() would work if the search action is done within updatepanel
看起来你试图显示整页回发的进度面板(模态弹出窗口)?如果搜索操作在updatepanel中完成,mdlPopup.Show()将起作用
In your scenario, try this instead - Step 1, set the TargetControlID of the modalpopupextender to a dummy hidden control - Step 2, added javascript call that shows the modalpopup $find('mdlPopup').show(); before the post-back call of search button's onclient event (just like adding a validation before post-back)
在你的场景中,试试这个 - 步骤1,将modalpopupextender的TargetControlID设置为虚拟隐藏控件 - 步骤2,添加javascript调用,显示modalpopup $ find('mdlPopup')。show();在搜索按钮的onclient事件的回拨之前(就像在回发之前添加验证一样)
James
#2
I think what you need to do here is separate the showing of the dialog and the binding from the fetching of the data.
我认为你需要做的是将对话框的显示和数据提取的绑定分开。
I would probably solve the problem using an approach like this:
我可能会使用这样的方法解决问题:
- Show Dialog and spin thread to go fetch the data. (the thread would put the data in the session cache, or a customised cache on a database.)
- Have the client poll the server for if the data is available (probably using AJAX calls to static page methods).
- When the data is available, hide the dialog and do the databind.
显示Dialog和旋转线程以获取数据。 (该线程会将数据放入会话缓存中,或者将数据库中的自定义缓存放入。)
让客户端轮询服务器以获取数据是否可用(可能使用对静态页面方法的AJAX调用)。
当数据可用时,隐藏对话框并执行数据绑定。
You can put additional checks/conditions around when the thread is started so that you don't start too many threads if the user presses search a number of times. I.e. if they haven't changed the search criteria then don't start a new search, but just continue polling.
您可以在线程启动时添加其他检查/条件,以便在用户按下搜索次数时不会启动太多线程。即如果他们没有更改搜索条件,则不要开始新搜索,只是继续轮询。