How do I force full post-back from a button within an UpdatePanel?
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>
-
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. – tsilb Feb 21 '13 at 21:05
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);
-
3Very 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! – OverMars Nov 29 '12 at 17:29
-
2You should be able to. When the control is created you can use AddHandler to create the trigger to your responding Subroutine – EvilDr Nov 30 '12 at 8:59
-
Absolutely right, its so simple and right there I'm almost embarrassed it never occurred to me. Very nice though.. – OverMars Nov 30 '12 at 19:14
-
-
2
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>
-
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. – Fandango68 Jul 5 '16 at 6:02
I had the same problem using an ImageButton inside a WebDataGrid.
I put the Line from EvilDr inside the preRender for the webdatagrid instead. Worked great!
for (int i = 0; i < wdgMyData.Rows.Count; i++)
{
ScriptManager.GetCurrent(this).RegisterPostBackControl((ImageButton)wdgMyData.Rows[i].Items[3].FindControl("btnDownloadExcel"));
}
Its an old question there is bit tricky approach as well, when everything is in update panels and you want to do full post back so that your Document.Ready code works on click.
1. Create a dummy button outside the update panel and click it from code behind like this
ScriptManager.RegisterStartupScript(Page, this.GetType(), "ResetDoc", "ResetDocumentReady();", true);
2. Define the function on front end like this
function ResetDocumentReady() {
$("[id$=DummyButton]").click();
}
NOTE: But the best way is using trigger, the answer posted by @Thibault Falise :)