![](/img/trans.png)
[英]How to refresh SSRS Report inside an ASP .NET Application without refreshing the whole page?
[英]ASP.net: Refresh GridView without refreshing the whole page? (AsyncPostBackTrigger really slow)
我是ASP.net的新手,正在尝试使一些超级慢的代码更快地运行。
当前,该代码在UpdatePanel中使用GridView。 UpdatePanel位于模式弹出窗口中。 每当打开该模式时,都必须刷新内容。 我们通过使用AsyncPostBackTrigger来做到这一点,据我了解,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来获取数据,然后从客户端手动重新填充表。 我想知道是否还有其他选择?
谢谢
您可能要考虑使用客户端网格,我已经使用Jquery datables相当一段时间了,主要是与ASPNET MVC一起使用,但您也可以将其与Web窗体一起使用。 真的很容易上手,这里有很多很好的例子,最好的部分是没有回发。 该工具具有内置的分页,排序,搜索等功能。
这是在Web表单上运行的Jquery数据表的一个很好的例子http://datatables.extrared.net/Sample/
这是您可以开始使用Jquery数据表https://datatables.net/的地方
您不一定需要PostBack才能打开弹出窗口。 这是一个使用jQuery UI Dialo g的代码段。
<div id="hiddenGrid" style="display: none">
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
<input type="button" value="Open Dialog" onclick="createPopup()" />
<script type="text/javascript">
function createPopup() {
var html = document.getElementById('hiddenGrid').innerHTML;
$('<div />').html(html).dialog({
resizable: false,
draggable: true,
modal: true,
width: 600,
height: 800,
create: function (event, ui) {
$(".ui-dialog-titlebar").html("<div onclick=\"closePopup()\" class=\"dialog-closeButton\"></div>");
},
open: function (event, ui) {
$('.ui-widget-overlay').bind('click', function () {
closePopup();
})
}
});
}
function closePopup() {
$(".ui-dialog-content").dialog("destroy");
}
</script>
但是,如果必须使用PostBack打开Modal,则可以检查它是否为Async PostBack,并跳过不需要的Page_Load中的项目。
protected void Page_Load(object sender, EventArgs e)
{
if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
{
//updatepanel page load
}
else
{
//normal page load
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.