문제

I'm working with a GridView inside an UpdatePanel. The after updating the data, clicking a refresh button tied to a DataBind() won't change anything on the page until at least 10 seconds after the data has been updated. Here is the relevant code:

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <div class="container-fluid">
            <asp:UpdatePanel runat="server" ID="UpdatePanel1" >

            <ContentTemplate>
                <div class="row">
                <div class="col-xs-12">  
                        <asp:Button ID="btnRefresh" runat="server" Text="Refresh"  CausesValidation="False" CssClass="btn btn-success" OnClick="btnRefresh_OnClick" /> 
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowSorting="True"
                            DataKeyNames="id" DataSourceID="sqldatasource" CssClass="table table-responsive table-hover"
                            OnRowDataBound="GridView1_OnRowDataBound"
                            OnRowCommand="GridView1_OnRowCommand"
                            >
                            <Columns>
                                <asp:CommandField ShowSelectButton="True" SelectText="Open" />
                                <!-- columns -->
                            </Columns>
                        </asp:GridView>
                    </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</form>

And the code behind:

    protected void btnRefresh_OnClick(object sender, EventArgs e)
    {
        GridView1.DataBind();
    }

I am using the same type of setup on another page without using the UpdateMode or Triggers and that has no problem data binding, but this will not.

도움이 되었습니까?

해결책

Answering for posterity. The SQL Data Source had caching enabled, so I removed that and databind works as expected without delay.

    <asp:SqlDataSource ID="sqlInProgress" runat="server" ConnectionString="<%$ ConnectionStrings:AppConnectionString %>" EnableCaching="true"  CacheDuration="30"
                       SelectCommand =" SELECT [Order].[id] as id, [Checker], [InternalComments], [CompanyName], [ProdLine], [ProductName],[Due], [Fulfillment], [FulfillmentX], [QA],  [QAX], FROM [Order], [Companies] where [Order].[CompanyName] = [Companies].[CompanyName] and [stage] = 'In progress' order by Due" />
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top