Force certain controls to do a full postback?

2019-08-02 14:06发布

问题:

I have some controls within an UpdatePanel. Included are some buttons. How can I make these buttons so that they do a full postback rather than a partial AJAX postback?

回答1:

Here's an example demonstrating how to use the PostbackTrigger instead of the AsyncPostbackTrigger:

ASPX Page:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="MyLabel" runat="server" />
        <br/>
        <asp:button ID="AjaxPostbackButton" Text="AJAX Postback" OnClick="AjaxPostbackButton_Click" runat="server" />
        <asp:button ID="FullPostbackButton" Text="Full Postback" OnClick="FullPostbackButton_Click" runat="server" />
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="AjaxPostbackButton" />
        <asp:PostBackTrigger ControlID="FullPostbackButton" />
    </Triggers>
</asp:UpdatePanel>

Code Behind:

private void AjaxPostbackButton_Click(object sender, EventArgs e)
{
    MyLabel.Text = "Ajax Postback: " + DateTime.Now;
}

private void FullPostbackButton_Click(object sender, EventArgs e)
{
    MyLabel.Text = "Full Postback: " + DateTime.Now;
}

Clicking on the "AJAX Postback" button will will update the panel using AJAX whereas the "Full Postback" button will reload the entire page.



回答2:

Use a PostbackTrigger rather than an AsyncPostbackTrigger