简体   繁体   English

ASP.net:刷新GridView而不刷新整个页面吗? (AsyncPostBackTrigger确实很慢)

[英]ASP.net: Refresh GridView without refreshing the whole page? (AsyncPostBackTrigger really slow)

I am new to ASP.net and trying to make some super slow code run faster. 我是ASP.net的新手,正在尝试使一些超级慢的代码更快地运行。

Currently, the code is using a GridView within an UpdatePanel. 当前,该代码在UpdatePanel中使用GridView。 The UpdatePanel sits within a modal popup window. UpdatePanel位于模式弹出窗口中。 Whenever that modal is opened, the content must be refreshed. 每当打开该模式时,都必须刷新内容。 We are doing this by using AsyncPostBackTrigger, which as I understand goes through the whole page generation cycle before returning and rendering the table. 我们通过使用AsyncPostBackTrigger来做到这一点,据我了解,AsyncPostBackTrigger在返回并呈现表之前会经历整个页面生成周期。

.aspx.cs .aspx.cs

public void UpdateWatchListPopup(object sender, System.EventArgs e)
{
    grdWatchList.DataBind();
}

.aspx: 的.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>

This is really slow (it takes 5 seconds to display the result), and it is not because there is a lot of data to return! 这确实很慢(显示结果需要5秒钟),而不是因为有很多数据要返回! My guess is that Page_Load() is doing doing a bunch of calculations unnecessary to refreshing that particular GridView. 我的猜测是Page_Load()正在做大量的计算,而不需要刷新特定的GridView。

Is there any other way to refresh the GridView asynchronously? 还有其他方法可以异步刷新GridView吗? I thought about using a WebMethod that fetches the data and then repopulate the table manually from client-side. 我考虑过使用一个WebMethod来获取数据,然后从客户端手动重新填充表。 I was wondering if there are other options? 我想知道是否还有其他选择?

Thank you 谢谢

You may want to consider using a client side grid, I've been using Jquery datables for quite some time now, mostly with ASPNET MVC but you can also use this with web forms. 您可能要考虑使用客户端网格,我已经使用Jquery datables相当一段时间了,主要是与ASPNET MVC一起使用,但您也可以将其与Web窗体一起使用。 It is really easy to get going, there are plenty of good examples out there and the best part is there are no postbacks. 真的很容易上手,这里有很多很好的例子,最好的部分是没有回发。 This tool comes with built in paging, sorting, search etc. 该工具具有内置的分页,排序,搜索等功能。

Heres' a good example of Jquery datatables running on web forms http://datatables.extrared.net/Sample/ 这是在Web表单上运行的Jquery数据表的一个很好的例子http://datatables.extrared.net/Sample/

And here is where you can get started with Jquery datatables https://datatables.net/ 这是您可以开始使用Jquery数据表https://datatables.net/的地方

You don't necessarily need a PostBack to open a popup. 您不一定需要PostBack才能打开弹出窗口。 Here is a snippet that uses the jQuery UI Dialo g. 这是一个使用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>

But if you must open the Modal with a PostBack, you can check if it is an Async PostBack and skip the items in Page_Load you don't need. 但是,如果必须使用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.

相关问题 如何在不刷新整个页面的情况下刷新ASP .NET应用程序中的SSRS报表? - How to refresh SSRS Report inside an ASP .NET Application without refreshing the whole page? 如何在gridview(asp.net)进入更新模式之前刷新整个页面? - How to refresh whole page before going into update mode in gridview(asp.net)? ASP.Net C# 在 GridView 中选择行而不更新整个页面 - ASP.Net C# Select Row in GridView without Updating the whole Page 如何防止在Asp.Net Gridview中的页面更改上刷新页面 - How to prevent page refresh on Page Changing in Asp.Net Gridview 在没有刷新页的情况下在asp.net中插入更新的记录时,如何自动更新Gridview? - how can i update Gridview automatically when a record inserted of updated in asp.net without refresh page? 如何在asp.net中手动刷新而无需更新gridview中的数据? - How to update data in gridview without manual refresh in asp.net? asp.net - gridview 更新刷新页面并重新加载数据 - asp.net - gridview update refresh page and reload data 真正简单的GridView ASP.NET问题 - Really simple GridView ASP.NET question ASP.NET DropDownList SelectedIndexChanged与UpdatePanel AsyncPostBackTrigger - ASP.NET DropDownList SelectedIndexChanged with UpdatePanel AsyncPostBackTrigger 如何在不刷新ASP.NET页的情况下更新数据库 - How to update database without refreshing the page ASP.NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM