无法关闭asp.net 4 ajax ModalPopupExtender

时间:2011-09-08 22:20:25

标签: asp.net ajax modalpopupextender

创建了一个用于保存数据的简单应用程序。我想:
1.确认用户想要保存数据(ConfirmButtonExtender)
2.通知用户数据已成功保存(带面板的ModalPopupExtender)

aspx代码:

<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="PanelSaveConfirmPopup"
    BehaviorID="ModalSaveConfirm" TargetControlID="PanelSaveConfirmPopup" DropShadow="true"
    CancelControlID="btnSaveConfirmedPopupOk">
</asp:ModalPopupExtender>
<asp:Panel ID="PanelSaveConfirmPopup" runat="server" Style="display: none;" BorderColor="Black"
    BorderStyle="Solid" BorderWidth="1px" Width="300px" Height="150px" BackColor="White"
    ForeColor="Black">
    <table width="99%">
        <tr>
            <td height="30">
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Label ID="Label19" runat="server" Text="Your data has been saved."></asp:Label>
            </td>
        </tr>
        <tr>
            <td height="45">
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Button ID="btnSaveConfirmedPopupOk" runat="server" Text="Okay" />
            </td>
        </tr>
    </table>
</asp:Panel>
<asp:Button ID="btnSave" runat="server" Text="Save" />
<asp:ConfirmButtonExtender ID="btnSave_ConfirmButtonExtender" runat="server" ConfirmText="Are you sure you want to save this?"
    Enabled="True" TargetControlID="btnSave">
</asp:ConfirmButtonExtender>
</asp:Content>
代码背后的代码:

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnSave_Click(sender As Object, e As System.EventArgs) Handles btnSave.Click
    ' Pretend to save data here
    ModalPopupExtender1.Show()
End Sub
End Class

我得到了两个弹出窗口 - 我的问题是ModalPopupExtender面板上的关闭按钮没有关闭modalpopup。有任何想法吗?谢谢!

1 个答案:

答案 0 :(得分:0)

我从链接中获得了一些提示它起作用的提示。将很快发布工作代码(我想我已经等了24个小时才能回答我自己的问题)。诀窍是创建一个虚拟按钮。虚拟按钮必须是asp.net visible = true但它可以使用Style =“display:none”隐藏在html中

工作代码是:

<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Button ID="btnSave" runat="server" Text="Save" />
<asp:ConfirmButtonExtender ID="btnSave_ConfirmButtonExtender" runat="server" ConfirmText="Are you sure you want to save this?"
    Enabled="True" TargetControlID="btnSave">
</asp:ConfirmButtonExtender>
<!-- We have to have a dummy control to hold the start event we handle in code behind -->
<asp:Button ID="MpeFakeTarget" runat="server" CausesValidation="False" Style="display: none" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="PanelSaveConfirmPopup"
    BehaviorID="ModalSaveConfirm" TargetControlID="MpeFakeTarget" DropShadow="true"
    CancelControlID="btnSaveConfirmedPopupOk">
</asp:ModalPopupExtender>
<asp:Panel ID="PanelSaveConfirmPopup" runat="server" Style="display: none;" BorderColor="Black"
    BorderStyle="Solid" BorderWidth="1px" Width="300px" Height="150px" BackColor="White"
    ForeColor="Black">
    <table width="99%">
        <tr>
            <td height="30">
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Label ID="Label19" runat="server" Text="Your data has been saved."></asp:Label>
            </td>
        </tr>
        <tr>
            <td height="45">
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Button ID="btnSaveConfirmedPopupOk" runat="server" Text="Okay" />
            </td>
        </tr>
    </table>
</asp:Panel>
</asp:Content>

我不确定我是否喜欢两个弹出窗口不同的事实?首先是要求人