异步更新 ASP.NET 面板
我需要一些帮助来解决这个问题:
情况: 我有一个用户控件(在 SharePoint 中),它读取查询字符串并使用异步事件处理它。当它很忙时,会显示一个旋转器。事件完成后,用户控件内的更新面板应更新并显示消息(+隐藏微调器)
代码:我有一个在 UserControl_Unload 事件上异步调用的函数。
private delegate void AsyncFunction(string activation);
void UserControl_Unload(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
AsyncFunction dlgt = new AsyncFunction(this.CheckUrl);
AsyncCallback callback = new AsyncCallback(FunctionCallBack);
IAsyncResult ar = dlgt.BeginInvoke(activationcode, callback, null);
}
}
private void CheckUrl(string lalala)
{
// Some code
}
用户控制标记:
<asp:UpdatePanel runat="server" id="pnlContent" updatemode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:UpdatePanel runat="server" id="pnlStatus" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Label runat="server" ID="lblMessage" />
<asp:LinkButton runat="server" ID="btnHome" Text="Terug naar welkom-pagina" PostBackUrl="<% $SPUrl:~sitecollection %>" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" id="pnlGegevens" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<div><asp:Image runat="server" ID="imgLoading" AlternateText="Loading..." CssClass="gb_pl_loadingImage" ImageUrl="<% $SPUrl:~sitecollection/Style Library/GB-VW Styles/Images/ajax-loader.gif %>"/></div>
<div class="gb_pl_loading">Even geduld aub. De gebruiker wordt geactiveerd...</div>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
这一切都很好,但是当我需要更新面板时,它不起作用。
private void FunctionCallBack(IAsyncResult test)
{
pnlContent.Update()
}
谁知道如何解决这个问题? (如果可能的话,只使用 asp、c# 或 javascript)
I need some help with this problem:
Situation:
I've got a usercontrol (in SharePoint) that reads query string and processes it with an asynchronous event. While it's busy, a spinner is shown. After the event is finished, the updatepanel inside the usercontrol should update and show the message (+ hide the spinner)
Code: I've got a function that's called asynchronously on the UserControl_Unload event.
private delegate void AsyncFunction(string activation);
void UserControl_Unload(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
AsyncFunction dlgt = new AsyncFunction(this.CheckUrl);
AsyncCallback callback = new AsyncCallback(FunctionCallBack);
IAsyncResult ar = dlgt.BeginInvoke(activationcode, callback, null);
}
}
private void CheckUrl(string lalala)
{
// Some code
}
User control markup:
<asp:UpdatePanel runat="server" id="pnlContent" updatemode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:UpdatePanel runat="server" id="pnlStatus" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Label runat="server" ID="lblMessage" />
<asp:LinkButton runat="server" ID="btnHome" Text="Terug naar welkom-pagina" PostBackUrl="<% $SPUrl:~sitecollection %>" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" id="pnlGegevens" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<div><asp:Image runat="server" ID="imgLoading" AlternateText="Loading..." CssClass="gb_pl_loadingImage" ImageUrl="<% $SPUrl:~sitecollection/Style Library/GB-VW Styles/Images/ajax-loader.gif %>"/></div>
<div class="gb_pl_loading">Even geduld aub. De gebruiker wordt geactiveerd...</div>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
This all works great, but when I need to update the panel, it doesn't work.
private void FunctionCallBack(IAsyncResult test)
{
pnlContent.Update()
}
Anyone who knows how to solve this? (if it's possible only use asp, c# or javascript)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是否可以从客户端触发异步操作?也就是说,显示您的页面但包含进行 Web 服务调用的 javascript?这样您至少有一些等待的时间,并且您的客户将收到通知,因为它发起了请求。
否则,我看不到异步操作完成后服务器如何更新已经发送给客户端的页面。
Is it possible to fire off the asynchronous operation from the client? That is, display your page but include javascript that makes a webservice call? That way you at least have something to wait for, and your client will get notified becuase it initiated the request.
Otherwise I don't see how the page, which is already gone to the client, could be updated by the server once the async op finishes.