0

There is a button outside update panel, the click event of the button binds grid view.

Grid view is inside the update panel and there is a link button inside the grid view.

Link button is causing full post back, i have looked online and tried different things but no luck so far.

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

<table>
<tr>
    <td>
        <asp:UpdatePanel ID="ContentUpdatePanel" runat="server">
            <ContentTemplate>
                <asp:GridView ID="gvMasterData" runat="server" AutoGenerateColumns="false" Width="200px" class="display">
                    <Columns>
                        <asp:TemplateField HeaderText="registration date" ItemStyle-Width="50">
                            <ItemTemplate>
                                <asp:Label ID="lblRegistrationDate" runat="server" Text='<%# Eval("registration_date") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="completed" ItemStyle-Width="50">
                            <ItemTemplate>
                                <asp:LinkButton Text='<%# Eval("completed") %>' ForeColor="Black" Font-Underline="false" runat="server" CommandName="Completed" CommandArgument="<%# Container.DataItemIndex %>" /> </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="pending" ItemStyle-Width="50">
                            <ItemTemplate>
                                <asp:LinkButton ID="MarkAsCompleteButton" Text='<%# Eval("pending") %>' ForeColor="Black" Font-Underline="false" runat="server" CommandName="Pending" CommandArgument="<%# Container.DataItemIndex %>" /> </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
    </td>
</table>

Code Behind

private void gvMasterData_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
    LinkButton lb = e.Row.FindControl("MarkAsCompleteButton") as LinkButton;
    ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);
  }
}
user1263981
  • 2,953
  • 8
  • 57
  • 98
  • A update inside of a update panel DOES cause the forms on-load command to fire each time - IT ALWAYS did! This is what we call a partial post back. Are you sure you not seeing a partial post back here? Update panels MOST certainly cause a post-back (they ALWAYS do). It just a question is this a full page post back or the partial one. I suspect you are seeing a post-back - but we ALWAYS do and ALWAYS did with a update panel. The major difference is that in these partial post-backs, your code behind can only update/change controls inside of that pane - not the whole page. – Albert D. Kallal Dec 26 '20 at 18:25

2 Answers2

0

Try to see this Full postback triggered by LinkButton inside GridView inside UpdatePanel

Saledan
  • 85
  • 9
0

When you use a update panel then the standard web page life cycle DOES occur. This is what we call a partial post back.

So the forms on-load event and near all of the standard web forms events WILL fire.

The only difference is that in these partial post backs, then the code stubs (code behind) can only modify controls inside of the panel - not controls outside. The code in the panel can certainly grab/use/look at and consume controls outside of the panel, but the values will be somewhat "static" or more clear such values will be the same when the full page was rendered since the last full page post back.

So are you confused or surprised that you seeing a post back? you will and you do!!

So perhaps you are seeing a post back (you will and do). However that post-back is not a full page post back. Any button or event that fires inside of the update panel will cause a post-back - but it is what we call a partial post back.

As such, then most of the web page standard events do fire - including the on-load event. As noted, the only difference here is that these partial post backs only sends up to the server the updated content inside of that up-date panel (not the whole page).

So you do of course in all cases will see events like on-load fire. And when the code behind stubs inside of that panel run, then as a normal course of action you can only deal with and modify controls inside of that panel with the code behind. If that code modifies controls outside of the panel, then in the classic standard "round trip" that occurs here DOES NOT include those controls outside of the update panel. So you can't and will not see the changes reflected in controls outside of the panel in that code behind that runs.

But a good old fashioned round trip DOES occur when using a up-date panel, it just that only controls and things inside of the panel make this classic round trip - not the whole page.

So update panels do and will cause post-backs, but they are considered partial ones.

So of course a update panel DOES cause a post-back - but it is only a partial post back. All of the classic round trip operations occur here - same as a full page post back, but it is limited to the update panel - not the whole page.

So it not clear if you "wondering" why you see a post back (you will and you do). Or if you are actually seeing a whole page post back. So ZERO surprise that a post-back is being triggered here (that does occur). The only question then is the post back you are seeing is a full page (should not occur), or you just seeing a page post back that is the partial one?

As noted, you will see a post back for events run inside of the panel. And thus as a normal operation things like page on-load does and will fire when using a update panel.

In other words, the whole standard page round trip for a update panel code and trigger DOES occur. This is a standard classic round trip that occurs here. As noted, the only difference is that such round trips only include the content inside of the panel, and thus other controls on the page should not be touched nor re-freshed.

Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51