Issue with multiple modular packages, ValidationSummary and UpdatePanels
I am having a problem where a page contains multiple ModalPopups, each containing a ValidationSummary element.
Here's the functionality I need:
- The user clicks a button and a Modal Popup with dynamic content appears based on the button the button was clicked on. (This function works. Buttons are wrapped in UpdatePanels and partial page callbacks .Show () in ModalPopup)
- The Save button in ModalPopup invokes client side validation and then invokes a full page popup message so that all ModalPopup disappears. (ModalPopup may disappear in another way - ModalPopup should just disappear after a successful save operation)
- If code errors occur during the save operation, the messages are added to the ValidationSummary (contained in ModalPopup) and ModalPopup is displayed again.
When ValidationSummary is added to the PopupPanel, ModalPopups no longer display correctly after a full page postback triggered by the Save button in the second PopupPanel. (the first panel continues to function correctly) PopupPanels are displayed and none of them are showing "Popped-Up", they are displayed in a row.
Any ideas on how to solve this?
EDIT: The functionality is different in each popup - so there must be two different ModalPopups.
EDIT 2: The Javascript error I was getting:
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 (n);}; Sys.Application.add_load (n);}) is not function
Absent ";" in the injected javascript. see answer below
Error status image (after clicking "PostBack Popup2")

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 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" />
<asp:Button ID="Popup1CancelButton" runat="server" Text="Cancel Popup1" />
<asp:UpdatePanel ID="Popup1UpdatePanel" runat="server">
<ContentTemplate>
<%--*************ISSUE HERE***************
The two ValidationSummary are causing an issue. When the second ModalPopup PostBack button is clicked,
Both ModalPopup become visible, but neither are "Popped-Up".
If ValidationSummary 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>
<br />
<br />
<br />
</asp:Panel>
<br />
<br />
<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 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" />
<asp:Button ID="Popup2CancelButton" runat="server" Text="Cancel Popup2" />
<asp:UpdatePanel ID="Popup2UpdatePanel" runat="server">
<ContentTemplate>
<%--*************ISSUE HERE***************
The two ValidationSummary are causing an issue. When the second ModalPopup PostBack button is clicked,
Both ModalPopup become visible, but neither are "Popped-Up".
If ValidationSummary 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>
<br />
<br />
<br />
</asp:Panel>
Code for
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 source to share
This is a problem using both ValidationSummary and ModalPopup.
see here: http://ajaxcontroltoolkit.codeplex.com/WorkItem/View.aspx?WorkItemId=12835
The problem is that there is no ";" between the two entered scripts.
Their solution is to create / use a custom server control that inherits from ValidationSummary, which injects ";" to the top of the script page to fix the error:
[ToolboxData("")]
public class AjaxValidationSummary : ValidationSummary
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true);
}
}
a source to share
There seems to be a panel validation bug in the modal popularity extension. to avoid the scenario, always put the resulting modal popup expander and panel at the bottom of the code. add the appropriate code at the bottom of the page
<% - This button invokes a check and a full page post. A full page callback will cause ModalPopup to be hidden. If there are errors in the code, the code behind will add a message to the ValidationSummary, and make ModalPopup visible again -%> <% - ************* OUTPUT HERE *********** **** The issue with ValidationSummary is causing the issue. When the second ModalPopup PostBack button is clicked, Both ModalPopup's become visible, but none of them "popped up". If ValidationSummary is removed, ModalPopups function correctly -%> <% - displays dynamically passed parameter during partial page writeback -%> Popup1 parameter:
a source to share