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

2019-01-10 18:23发布

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

5条回答
等我变得足够好
2楼-- · 2019-01-10 18:41

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"));
}
查看更多
小情绪 Triste *
3楼-- · 2019-01-10 18:48

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 :)

查看更多
闹够了就滚
4楼-- · 2019-01-10 18:50

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>
查看更多
三岁会撩人
5楼-- · 2019-01-10 18:56

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>
查看更多
可以哭但决不认输i
6楼-- · 2019-01-10 18:59

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);
查看更多
登录 后发表回答