views:

412

answers:

2

I am having an issue when a page contains multiple ModalPopups each containing a ValidationSummary Control.

Here is the functionality I need:

  1. A user clicks a button and a Modal Popup appears with dynamic content based on the button that was clicked. (This functionality is working. Buttons are wrapped in UpdatePanels and the partial page postback calls .Show() on the ModalPopup)
  2. "Save" button in ModalPopup causes client side validation, then causes a full page postback so the entire ModalPopup disappears. (ModalPopup could disappear another way - the ModalPopup just needs to disappear after a successful save operation)
  3. If errors occur in the codebehind during Save operation, messages are added to the ValidationSummary (contained within the ModalPopup) and the ModalPopup is displayed again.

When the ValidationSummary's are added to the PopupPanel's, the ModalPopups no longer display correctly after a full page postback caused by the "Save" button within the second PopupPanel. (the first panel continues to function correctly) Both PopupPanels are displayed, and neither is "Popped-Up", they are displayed in-line.

Any ideas on how to solve this?

EDIT: Functionality in each Popup is different - that is why there must be two different ModalPopups.

EDIT 2: Javascript error I was receiving:

function () { Array.remove(Page_ValidationSummaries, document.getElementById(VALIDATION_SUMMARY_ID)); } (function () { var fn = function () { AjaxControlToolkit.ModalPopupBehavior.invokeViaServer("MODAL_POPUP_ID", true); Sys.Application.remove_load(fn); }; Sys.Application.add_load(fn); }) is not a function

Missing ";" in injected javascript. see answer below

Image of Error State (after "PostBack Popup2" button has been clicked) alt text

ASPX markup

<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>

Code Behind

protected void Popup1ShowButton_Click(object sender, EventArgs e)
    {
        Button btn = sender as Button;

        //Dynamically pass parameter to ModalPopup during partial page postback
        Popup1Parameter.Text = btn.CommandArgument;
        Popup1ModalPopup.Show();
    }
    protected void Popup1PostBackButton_Click(object sender, EventArgs e)
    {
        //if there is an error, add a message to the validation summary and
        //show the ModalPopup again

        //TODO: add message to validation summary

        //show ModalPopup after page refresh (request/response)
        Popup1ModalPopup.Show();
    }


    protected void Popup2ShowButton_Click(object sender, EventArgs e)
    {
        Button btn = sender as Button;

        //Dynamically pass parameter to ModalPopup during partial page postback
        Popup2Parameter.Text = btn.CommandArgument;
        Popup2ModalPopup.Show();
    }
    protected void Popup2PostBackButton_Click(object sender, EventArgs e)
    {
        //***********After This is when the issue appears**********************

        //if there is an error, add a message to the validation summary and
        //show the ModalPopup again

        //TODO: add message to validation summary

        //show ModalPopup after page refresh (request/response)
        Popup2ModalPopup.Show();
    }
A: 

Did you seto a different "ValidationGroup" of each popup (ValidationSummary + validators) ?

DavRob60
Yes, ValidationGroup's were used.
Aaron Hoffman
+2  A: 

This is an issue with using both ValidationSummary and ModalPopup.

see here: http://ajaxcontroltoolkit.codeplex.com/WorkItem/View.aspx?WorkItemId=12835

The problem is that there is a missing ";" between the two injected scripts.

Their solution is to create/use a custom server control that inherits from ValidationSummary, that injects a ";" into the page startup script to fix the bug:

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