I have an ASPX page that I've built that displays results from a sql pull in a gridview when you click the refresh button. Currently everything (including the button) are inside the updatepanel. I run UpdateProgress to show a loading wheel before the results populate. I use an AsyncPostBackTrigger so that only the updatepanel refreshes and not the entire page. All of this works great!

The problem is this... The button only works on the first click! Any subsequent clicks, the program is not aware of. I know this becasue I've added in the messagebox (windows.system.forms has been added to project) to show something on second click and that never pops up. Ideally i'll want to clear the datagrid and repopulate the gridview with new data but when I recognized the button stopped working this is how I began troubleshooting.

Below is the ASPX Page Code.

    <asp:ScriptManager EnablePartialRendering="true" ID="ScriptManager1" runat="server" AsyncPostBackTimeout="400" ></asp:ScriptManager>

    <asp:UpdatePanel ID="UpdatePanel1" ChildrenAsTriggers="true" runat="server" UpdateMode="Conditional">

        <ContentTemplate>
            <asp:Button ID="btnRefreshAlerts" runat="server" OnClick="btnRefreshAlerts_Click" Text="Pull/Refresh" Width="84px" Visible="True" UseSubmitBehavior="False"/>

        <asp:GridView ID="GridView1" AllowSorting="false" BackColor="White" BorderColor="Black" Font-Names="Calibri" Font-Size="Small" ForeColor="Black" runat="server">
            <RowStyle BackColor="#F0F0F0" BorderColor="#666666" />
        </asp:GridView>

             </ContentTemplate>
       <Triggers>
     <asp:AsyncPostBackTrigger ControlID="btnRefreshAlerts" EventName="Click" />
           </Triggers>
   </asp:UpdatePanel>

    <asp:UpdateProgress ID="updateProgress" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
    <ProgressTemplate>
        <div id="progressBackgroundFilter"><div style="text-align:center">
        </div>
        <div id="processMessage"><div style="text-align:center">
            Loading...<br />
            <br />
            <img alt="Loading" src="images/ajax-loader.gif" />
        </div>
    </ProgressTemplate>
</asp:UpdateProgress>

</form>

Here is the CS Code Behind File

protected void btnRefreshAlerts_Click(object sender, EventArgs e)

        {
if (counter == 0)
{

        Fill_DataGrid(sender, e);
}
else
{
    //I don't even want this to happen in the final product - i'll want to instead clear the gridview and repull/populate the gridview with new data
    MessageBox.Show("I recognize this is second press");

}
}

I run a query and increment the counter by one like this... (also the counter is initialized as 0 somewhere up the Code behind file and well before the Fill_DataGrid operation)

    protected void Fill_DataGrid(object sender, EventArgs e)
{

    //Load ALERTS into Datatable and then into data grid
    using (SqlConnection openCon = new SqlConnection("CONNECTIONSTRING"))
    {
        using (SqlCommand PullData = new SqlCommand())
        {

            PullData.Connection = openCon;
            PullData.CommandText = "CRAZYQUERY";
            openCon.Open();
            PullData.CommandTimeout = 300000;
            AlertGrid.Load(PullData.ExecuteReader());
            openCon.Close();

        }


        GridView1.DataSource = AlertGrid;
        GridView1.DataBind();
        UpdatePanel1.Update();
        counter = counter + 1;


    }

    }

Related posts

Recent Viewed