How do I force full post-back from a button within an UpdatePanel?

79,234

Solution 1

You can use the Triggers property of the UpdatePanel to register actions that trigger a full postback.

Add a PostBackTrigger object to that property, containig the ControlID of the control which needs to trigger a full postback.

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
        ...
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="myFullPostBackControlID" />
    </Triggers>
</asp:UpdatePanel>

Solution 2

Just adding this because nobody else has. It is possible to do this in code-behind in one line of code without any of the above methods. Just put this in page_load:

Visual Basic

ScriptManager.GetCurrent(Me).RegisterPostBackControl(myButtonID)

C#

ScriptManager.GetCurrent(this).RegisterPostBackControl(myButtonID);

Solution 3

From here:

Use the PostBackTrigger control to enable controls inside an UpdatePanel to cause a postback instead of performing an asynchronous postback.

 <Triggers>
    <asp:PostBackTrigger ControlID="controlID" />
 </Triggers>
Share:
79,234
Andre Pena
Author by

Andre Pena

Brazilian frontend engineer living in Berlin. Follow me on Twitter: https://twitter.com/andrerpena

Updated on July 05, 2022

Comments

  • Andre Pena
    Andre Pena almost 2 years

    How do I force full post-back from a button within an UpdatePanel?

  • OverMars
    OverMars over 11 years
    Very nice, after hours of searching, finally a solution that works. The issue was all my controls (update panel and button) were being created in code behind so a postbacktrigger could not be set. Thanks!
  • EvilDr
    EvilDr over 11 years
    You should be able to. When the control is created you can use AddHandler to create the trigger to your responding Subroutine
  • OverMars
    OverMars over 11 years
    Absolutely right, its so simple and right there I'm almost embarrassed it never occurred to me. Very nice though..
  • tsilb
    tsilb about 11 years
    I have an Infragistics UltraWebGrid with a column that consists of buttons. I had a problem where clicking on the buttons would fire their event handlers, which in turn refreshes the grid, but the grid would not actually refresh visibly until the second click. Putting the buttons in an UpdatePanel and adding these triggers solved the problem.
  • Fandango68
    Fandango68 about 8 years
    What is 'Me'? Does not exist in current context error
  • EvilDr
    EvilDr about 8 years
    Me is visual basic for the page. I think in C# you can use this or page
  • Fandango68
    Fandango68 almost 8 years
    This only works with ONE updatepanel and ONE trigger button. What if the updatepanel is inside a Gridview row, where each updatepanel and trigger button has a unique ClientID?
  • Fandango68
    Fandango68 almost 8 years
    Hmm yeah but won't work if inside that UpdatePanel you have a GridView with Page numbers for example. Change to a new page and the triggers no longer work.
  • EvilDr
    EvilDr almost 8 years
    In the GridView.RowCreated method, apply exactly the same logic to achieve the same
  • jmsandy
    jmsandy almost 5 years
    Thanks, you helped me in another problem with AjaxToolKit.HtmlEditor within popup.