Force certain controls to do a full postback?
I have some c开发者_高级运维ontrols 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?
Use a PostbackTrigger rather than an AsyncPostbackTrigger
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.
精彩评论