Вопрос

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