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>
Author by
Andre Pena
Brazilian frontend engineer living in Berlin. Follow me on Twitter: https://twitter.com/andrerpena
Updated on July 05, 2022Comments
-
Andre Pena almost 2 years
How do I force full post-back from a button within an UpdatePanel?
-
OverMars over 11 yearsVery 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 over 11 yearsYou should be able to. When the control is created you can use AddHandler to create the trigger to your responding Subroutine
-
OverMars over 11 yearsAbsolutely right, its so simple and right there I'm almost embarrassed it never occurred to me. Very nice though..
-
tsilb about 11 yearsI 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 about 8 yearsWhat is 'Me'? Does not exist in current context error
-
EvilDr about 8 yearsMe is visual basic for the page. I think in C# you can use
this
orpage
-
Fandango68 almost 8 yearsThis 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 almost 8 yearsHmm 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 almost 8 yearsIn the GridView.RowCreated method, apply exactly the same logic to achieve the same
-
jmsandy almost 5 yearsThanks, you helped me in another problem with AjaxToolKit.HtmlEditor within popup.