How to do a postback after exit ModalPopupExtender with an UpdatePanel
I have a Button on a page. This button opens a ModalPopupExtender. Inside this popup there is an UpdatePanel for showing an error before hiding the popup. But when I click on the button ok and when there is no error in the popup, I would like to update the information of a Label (lblInfo) in the main page. How can I do that?
Thank you.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestModalPopupExtender.WebForm1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.pvPanel
{
width: 630px;
margin: 0px;
padding: 0px;
font-family: Arial, Helvetica, sans-serif;
font-size: small;
}
.modalBox
{
background-color: #ffffff;
border: 2px Solid #707070;
padding: 8px 5px 8px 5px;
font-family: Arial, Helvetica, sans-serif;
font-size: small;
}
.modalBackground
开发者_如何学Python {
background-color: #b0b0b0;
filter: alpha(opacity=70);
opacity: 0.7px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server">
</ajax:ToolkitScriptManager>
<br />
<br />
<asp:Button ID="btnOpen" runat="server" Text="Open popup" />
<br />
<br />
<asp:Label ID="lblInfo" runat="server" Text=""></asp:Label>
<%-- Popup --%>
<asp:Panel ID="Panel1" runat="server" CssClass="modalBox">
<br />
<br />
<asp:CheckBox ID="chkState" runat="server" Text="Get an error!" />
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnOk" />
</Triggers>
<ContentTemplate>
<asp:Label ID="lblError" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<br />
<asp:Button ID="btnOk" runat="server" Text="Ok" OnClick="btnOk_Click" />
<br />
<br />
</asp:Panel>
<ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnOpen"
PopupControlID="Panel1" BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
</div>
</form>
</body>
</html>
protected void btnOk_Click(object sender, EventArgs e)
{
if (chkState.Checked)
{
lblError.Text = "Error! Try again.";
return;
}
ModalPopupExtender1.Hide();
lblInfo.Text = "The label is now updated!";
}
Put the lblInfo inside another update panel, let call it UpdatePanel2.
Then call UpdatePanel2.update() after you set the new lblInfo's text.
精彩评论