2

當頁面包含多個ModalPopup,每個都包含ValidationSummary控件時,我遇到問題。Multiple ModalPopups,ValidationSummary和UpdatePanels問題

這裏是我所需要的功能:

  1. 用戶點擊了一個按鈕和一個模式彈出出現基於被點擊的按鈕,動態內容。 (此功能正在工作。按鈕封裝在UpdatePanels中,並且部分頁面回發調用ModalPopup上的.Show()
  2. ModalPopup中的「保存」按鈕導致客戶端驗證,然後導致整個頁面回發,因此整個ModalPopup消失。 (ModalPopup可能以另一種方式消失 - ModalPopup只需在成功保存操作後消失)
  3. 如果在保存操作期間代碼隱藏中發生錯誤,則會將消息添加到ValidationSummary(包含在ModalPopup中),並再次顯示ModalPopup 。

當ValidationSummary被添加到PopupPanel的時候,ModalPopups在第二個PopupPanel中的「保存」按鈕導致的完整頁面回發後不再正確顯示。 (第一個面板繼續正常運行)兩個PopupPanel都顯示出來,並且都不是「彈出式」面板顯示。

關於如何解決這個問題的任何想法?

編輯:每個彈出窗口的功能是不同的 - 這就是爲什麼必須有兩個不同的ModalPopups。

編輯2:JavaScript錯誤我被接收:

函數(){ Array.remove(Page_ValidationSummaries,的document.getElementById(VALIDATION_SUMMARY_ID)); } (函數(){ VAR FN =函數(){ AjaxControlToolkit.ModalPopupBehavior.invokeViaServer( 「MODAL_POPUP_ID」,TRUE); Sys.Application.remove_load(FN); }; Sys.Application.add_load( FN); })不是函數

缺少 「;」在注入JavaScript。見( 「回傳Popup2」 按鈕被點擊後)低於

錯誤狀態的圖片回答 alt text

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> 

代碼隱藏

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(); 
    } 

回答

4

這是使用ValidationSummary和ModalPopup的問題。

在這裏看到:http://ajaxcontroltoolkit.codeplex.com/WorkItem/View.aspx?WorkItemId=12835

的問題是,有一個失蹤 「;」在兩個注入的腳本之間。

他們的解決方案是創建/使用繼承自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); 
    } 
} 
+0

是否可以在不創建自定義控件的情況下解決此問題? – ravidev 2012-07-05 12:39:53

+1

哇 - 我記錄它只是說'哇'。 – 2013-06-12 17:16:47

0

你有沒有瀨每個彈出窗口(ValidationSummary + validators)的不同「ValidationGroup」?

+0

是,使用的ValidationGroup的。 – 2010-04-26 19:13:19

1

將所有<asp:ValidationSummary控件放在文檔的末尾。 錯誤將被解決。

0

它似乎有模式彈出擴展與面板驗證摘要中的錯誤。爲了避免這種情況,總是將驗證摘要模式彈出式擴展器和麪板放在代碼的底部。 在底部添加相應的代碼頁的

<% - 這個按鈕導致驗證和整版後回來。整頁回發將導致ModalPopup被隱藏。 如果在代碼中的錯誤背後,後面的代碼將添加一個消息在ValidationSummary, ,使ModalPopup再次可見 - %>   <% - ********* ****問題*************** 這兩個ValidationSummary是造成問題。當單擊第二個ModalPopup的回發按鈕時, 兩個ModalPopup都可見,但都不是「彈出」。 如果的ValidationSummary的被刪除,既ModalPopups正常進行 - %> <% - 部分頁面後回過程中顯示動態傳遞放慢參數 - %> Popup1參數: