使用UpdatePanel退出ModalPopupExtender后如何进行回发

时间:2010-07-08 09:26:08

标签: asp.net ajax updatepanel modalpopupextender

我在页面上有一个按钮。此按钮可打开ModalPopupExtender。在这个弹出窗口中有一个UpdatePanel,用于在隐藏弹出窗口之前显示错误。但是当我点击按钮确定并且弹出窗口中没有错误时,我想在主页面中更新Label(lblInfo)的信息。我怎么能这样做?

谢谢。

<%@ 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
        {
            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!";
    }

1 个答案:

答案 0 :(得分:2)

将lblInfo放在另一个更新面板中,我们称之为UpdatePanel2。

然后在设置新的lblInfo文本后调用UpdatePanel2.update()。