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">

            <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:AsyncPostBackTrigger ControlID="btnRefreshAlerts" EventName="Click" />

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


Here is the CS Code Behind File

protected void btnRefreshAlerts_Click(object sender, EventArgs e)

if (counter == 0)

        Fill_DataGrid(sender, e);
    //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";
            PullData.CommandTimeout = 300000;


        GridView1.DataSource = AlertGrid;
        counter = counter + 1;



Related posts

Recent Viewed