【发布时间】:2017-06-13 15:53:59
【问题描述】:
我是 ASP.net 的新手,正在尝试让一些超级慢的代码运行得更快。
目前,代码在 UpdatePanel 中使用 GridView。 UpdatePanel 位于模式弹出窗口中。每当打开该模式时,必须刷新内容。我们通过使用 AsyncPostBackTrigger 来做到这一点,据我所知,它会在返回和呈现表格之前经历整个页面生成周期。
.aspx.cs
public void UpdateWatchListPopup(object sender, System.EventArgs e)
{
grdWatchList.DataBind();
}
.aspx:
<asp:UpdatePanel ID="UpdatePanel3" runat="server" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateWatchListPopupBtn" EventName="Click" />
</Triggers>
<ContentTemplate>
<div style="display:none">
<asp:Button ID="UpdateWatchListPopupBtn" runat="server" Text="" OnClick="UpdateWatchListPopup" />
</div>
<asp:GridView ID="grdWatchList" OnSorting="grdWatchList_Sorting" runat="server" OnRowCreated="grdWatchList_RowCreated" OnRowDataBound="grdWatchList_RowDataBound" AllowSorting="true" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
这真的很慢(显示结果需要5秒),并不是因为要返回的数据很多!我的猜测是 Page_Load() 正在做一堆不必要的计算来刷新特定的 GridView。
还有其他异步刷新 GridView 的方法吗?我考虑过使用 WebMethod 来获取数据,然后从客户端手动重新填充表。我想知道是否还有其他选择?
谢谢
【问题讨论】:
-
第一次加载页面也需要 5 秒吗?
-
是的。基本上,整个应用程序都在一个页面中,并且在开始时获取所有数据。
标签: c# asp.net gridview updatepanel postback