Asp.net 多个ModalPopup、ValidationSummary和UpdatePanel出现问题

Asp.net 多个ModalPopup、ValidationSummary和UpdatePanel出现问题,asp.net,updatepanel,ajaxcontroltoolkit,modalpopupextender,validationsummary,Asp.net,Updatepanel,Ajaxcontroltoolkit,Modalpopupextender,Validationsummary,当一个页面包含多个modalpopup,每个modalpopup都包含一个ValidationSummary控件时,我遇到了一个问题 以下是我需要的功能: 用户单击按钮,将显示一个模式弹出窗口,其中包含基于所单击按钮的动态内容。(此功能正在运行。按钮包装在UpdatePanels中,部分页面回发调用了ModalPopup上的.Show()) ModalPopup中的“保存”按钮会导致客户端验证,然后导致整页回发,因此整个ModalPopup将消失。(ModalPopup可能以另一种方式消失-Mo

当一个页面包含多个modalpopup,每个modalpopup都包含一个ValidationSummary控件时,我遇到了一个问题

以下是我需要的功能:

  • 用户单击按钮,将显示一个模式弹出窗口,其中包含基于所单击按钮的动态内容。(此功能正在运行。按钮包装在UpdatePanels中,部分页面回发调用了ModalPopup上的.Show())
  • ModalPopup中的“保存”按钮会导致客户端验证,然后导致整页回发,因此整个ModalPopup将消失。(ModalPopup可能以另一种方式消失-ModalPopup只需在成功保存操作后消失)
  • 如果在保存操作期间代码隐藏中出现错误,消息将添加到ValidationSummary(包含在ModalPopup中),并且ModalPopup将再次显示
  • 当ValidationSummary添加到PopupPanel中时,由于第二个PopupPanel中的“Save”(保存)按钮导致整个页面回发后,ModalPopup将不再正确显示。(第一个面板继续正常工作)两个PopupPanel都会显示,并且都不会“弹出”,而是以直线方式显示

    有没有办法解决这个问题

    编辑:每个弹出窗口中的功能不同-这就是为什么必须有两个不同的ModalPopup

    编辑2:我收到的Javascript错误:

    函数(){ remove(Page_ValidationSummaries,document.getElementById(VALIDATION_SUMMARY_ID)); } (功能(){ var fn=函数(){ AjaxControlToolkit.ModalPopupBehavior.invokeViaServer(“模态弹出窗口ID”,true); 系统应用程序移除负载(fn); }; 系统应用程序添加负载(fn); })不是一个函数

    在注入的javascript中缺少“;”。请参见下面的答案

    错误状态的图像(单击“PostBack Popup2”按钮后)

    ASPX标记

    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <%--*********************************************************************
            Popup1
            *********************************************************************--%>
        <asp:UpdatePanel ID="Popup1ShowButtonUpdatePanel" runat="server">
            <ContentTemplate>
                <%--This button will cause a partial page postback and pass a parameter to the Popup1ModalPopup in code behind
                and call its .Show() method to make it visible--%>
                <asp:Button ID="Popup1ShowButton" runat="server" Text="Show Popup1" OnClick="Popup1ShowButton_Click"
                    CommandArgument="1" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <%--Hidden Control is used as ModalPopup's TargetControlID .Usually this is the ID of control that causes the Popup,
            but we want to control the modal popup from code behind --%>
        <asp:HiddenField ID="Popup1ModalPopupTargetControl" runat="server" />
        <ajax:ModalPopupExtender ID="Popup1ModalPopup" runat="server" TargetControlID="Popup1ModalPopupTargetControl"
            PopupControlID="Popup1PopupControl" CancelControlID="Popup1CancelButton">
        </ajax:ModalPopupExtender>
        <asp:Panel ID="Popup1PopupControl" runat="server" CssClass="ModalPopup" Style="width: 600px;
            background-color: #FFFFFF; border: solid 1px #000000;">
            <%--This button causes validation and a full-page post back.  Full page postback will causes the ModalPopup to be Hid.
                If there are errors in code behind, the code behind will add a message to the ValidationSummary,
                and make the ModalPopup visible again--%>
            <asp:Button ID="Popup1PostBackButton" runat="server" Text="PostBack Popup1" OnClick="Popup1PostBackButton_Click" />&nbsp;
            <asp:Button ID="Popup1CancelButton" runat="server" Text="Cancel Popup1" />
            <asp:UpdatePanel ID="Popup1UpdatePanel" runat="server">
                <ContentTemplate>
                    <%--*************ISSUE HERE***************
                    The two ValidationSummary's are causing an issue.  When the second ModalPopup's PostBack button is clicked,
                    Both ModalPopup's become visible, but neither are "Popped-Up".
                    If ValidationSummary's are removed, both ModalPopups Function Correctly--%>
                    <asp:ValidationSummary ID="Popup1ValidationSummary" runat="server" />
                    <%--Will display dynamically passed paramter during partial page post-back--%>
                    Popup1 Parameter:<asp:Literal ID="Popup1Parameter" runat="server"></asp:Literal><br />
                </ContentTemplate>
            </asp:UpdatePanel>
            &nbsp;<br />
            &nbsp;<br />
            &nbsp;<br />
        </asp:Panel>
        &nbsp;<br />
        &nbsp;<br />
        &nbsp;<br />
        <%--*********************************************************************
            Popup2
            *********************************************************************--%>
        <asp:UpdatePanel ID="Popup2ShowButtonUpdatePanel" runat="server">
            <ContentTemplate>
                <%--This button will cause a partial page postback and pass a parameter to the Popup2ModalPopup in code behind
                and call its .Show() method to make it visible--%>
                <asp:Button ID="Popup2ShowButton" runat="server" Text="Show Popup2" OnClick="Popup2ShowButton_Click"
                    CommandArgument="2" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <%--Hidden Control is used as ModalPopup's TargetControlID .Usually this is the ID of control that causes the Popup,
            but we want to control the modal popup from code behind --%>
        <asp:HiddenField ID="Popup2ModalPopupTargetControl" runat="server" />
        <ajax:ModalPopupExtender ID="Popup2ModalPopup" runat="server" TargetControlID="Popup2ModalPopupTargetControl"
            PopupControlID="Popup2PopupControl" CancelControlID="Popup2CancelButton">
        </ajax:ModalPopupExtender>
        <asp:Panel ID="Popup2PopupControl" runat="server" CssClass="ModalPopup" Style="width: 600px;
            background-color: #FFFFFF; border: solid 1px #000000;">
            <%--This button causes validation and a full-page post back.  Full page postback will causes the ModalPopup to be Hid.
                If there are errors in code behind, the code behind will add a message to the ValidationSummary,
                and make the ModalPopup visible again--%>
            <asp:Button ID="Popup2PostBackButton" runat="server" Text="PostBack Popup2" OnClick="Popup2PostBackButton_Click" />&nbsp;
            <asp:Button ID="Popup2CancelButton" runat="server" Text="Cancel Popup2" />
            <asp:UpdatePanel ID="Popup2UpdatePanel" runat="server">
                <ContentTemplate>
                    <%--*************ISSUE HERE***************
                    The two ValidationSummary's are causing an issue.  When the second ModalPopup's PostBack button is clicked,
                    Both ModalPopup's become visible, but neither are "Popped-Up".
                    If ValidationSummary's are removed, both ModalPopups Function Correctly--%>
                    <asp:ValidationSummary ID="Popup2ValidationSummary" runat="server" />
                    <%--Will display dynamically passed paramter during partial page post-back--%>
                    Popup2 Parameter:<asp:Literal ID="Popup2Parameter" runat="server"></asp:Literal><br />
                </ContentTemplate>
            </asp:UpdatePanel>
            &nbsp;<br />
            &nbsp;<br />
            &nbsp;<br />
        </asp:Panel>
    

    您是否为每个弹出窗口(ValidationSummary+validators)设置了不同的“ValidationGroup”

    这是同时使用ValidationSummary和ModalPopup的问题

    请看这里:

    问题是两个注入脚本之间缺少“;”

    他们的解决方案是创建/使用一个从ValidationSummary继承的自定义服务器控件,该控件在页面启动脚本中注入“;”以修复错误:

    [ToolboxData("")]
    public class AjaxValidationSummary : ValidationSummary
    {
      protected override void OnPreRender(EventArgs e)
      {
        base.OnPreRender(e);
        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true);
      }
    }
    

    把所有的
    放在面板中的验证摘要中,模态pop扩展器似乎有bug。为了避免这种情况,请始终将验证摘要模式弹出扩展程序和面板放在代码的底部。
    在页面底部添加相应的代码

    Popup1参数:

    是的,使用了ValidationGroup。是否可以在不创建自定义控件的情况下解决此问题?哇-我将其登录到只是为了说“哇”。
    [ToolboxData("")]
    public class AjaxValidationSummary : ValidationSummary
    {
      protected override void OnPreRender(EventArgs e)
      {
        base.OnPreRender(e);
        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true);
      }
    }