2011-05-27 41 views
3

如何防止我的asp:ModalPopupExtender在回发到服务器之后或期间关闭?防止ModalPopupExtender在PostBack期间/之后关闭

这里是我的代码:

JAVASCRIPT

// Confirm popup Ok button 
function OnOk() { 
    $('#confirmPopup').hide(); 
    ClickSaveButton();  // does a postback 
    ShowGridPopup(); 
} 

ASP.NET AJAX

<asp:ModalPopupExtender BehaviorID="confirmPopup" ID="confirmPopup" runat="server" 
     TargetControlID="butConfirm" PopupControlID="ConfirmView" BackgroundCssClass="modalBackground" 
     OnOkScript="OnOk();" OnCancelScript="OnCancel();" 
     OkControlID="yesButton" CancelControlID="noButton"> 
    </asp:ModalPopupExtender> 

没有,如果我之前或回传方法ClickSaveButton()后调用ShowGridPopup()事,弹出窗口仍然消失。我怎样才能防止这一点?

编辑

下面是ShowGridPopup()和我已经找到一种方法来通过通过这个代码ClickSaveButton()

function ShowGridPopup() { 
    if (getID() == "Popup1") { 
     ShowGridPopup1(); 
    } else if (getID() == "Popup2") { 
     ShowGridPopup2(); 
    } 
} 

function ClickSaveButton() { 
    var _id = $('a[id$="butSave"]').attr("ID"); 
    __doPostBack(_id.replace("_", "$"), ''); 
} 
+0

在'ClickSaveButton();',你会执行一个完整的回发或一个asyncpostback?此外,'ClickSaveButton'和'ShowGridPopup'的代码将有助于发现问题。 – DavRob60 2011-05-30 13:01:48

+0

我将代码添加为编辑... – 2011-05-30 14:35:04

回答

1

,这里是我的解决办法:你要创建一个新的HiddenField控制器从ASP中的服务器端将用于存储要在回发后显示的ModalPopupExtender的ID,如果没有弹出窗口显示,则将其设置为空。

<!-- Grid Popup ID: to obtain the grid popup ID from server-side --> 
<asp:HiddenField id="gridPopupID" runat="server" value="" /> 

接下来,我们需要才使用保存事件的ID设置为HiddenField现在

// Confirm popup Ok button 
function OnOk() { 
    $('#confirmPopup').hide();       // hides the current confirmation popup 
    $("#<%= gridPopupID.ClientID %>").val(getID());  // set the ID to the hiddenField. 
    ClickSaveButton();         // simulates the click of the save button 
} 

,在后面的代码,我们需要做的是检查HiddenField的价值文本字段,我们可以在正确的弹出窗口上做一个.Show()

Protected Sub OnSaveAssociation(ByVal sender As Object, ByVal e As EventArgs) Handles butSaveAssociation.Click 

' ommited code: save changes to back end 

      ' determine which popup to show 
      Dim _id As String = gridPopupID.Value 
      Select Case _id 
       Case "Popup1" 
        gridPopup1.Show() 
        gridPopupID.Value = Nothing 
       Case "Popup2" 
        gridPopup2.Show() 
        gridPopupID.Value = Nothing 
      End Select 

End Sub 
9

你应该使用UpdatePanel,所以ModalPopupExtender不会回发后隐藏。见下面这个例子:

.aspx的:

<body> 
    <form id="form1" runat="server"> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 
    <div> 
     <asp:UpdatePanel ID="udpOutterUpdatePanel" runat="server"> 
      <ContentTemplate> 

       <asp:Button ID="ButtonShow" runat="server" Text="Show Popup" OnClick="ButtonShow_Click" />     


       <input id="dummy" type="button" style="display: none" runat="server" /> 
       <ajaxToolkit:ModalPopupExtender runat="server" 
         ID="mpeThePopup" 
         TargetControlID="dummy" 
         PopupControlID="pnlModalPopUpPanel" 
         BackgroundCssClass="modalBackground"       
         DropShadow="true"/> 
       <asp:Panel ID="pnlModalPopUpPanel" runat="server" CssClass="modalPopup"> 
        <asp:UpdatePanel ID="udpInnerUpdatePanel" runat="Server" UpdateMode="Conditional"> 
         <ContentTemplate> 
          Message 
          <asp:Button ID="ButtonClose" runat="server" Text="Close Popup" OnClick="ButtonClose_Click" />                 
         </ContentTemplate>  
        </asp:UpdatePanel> 
       </asp:Panel> 

      </ContentTemplate> 
     </asp:UpdatePanel> 
    </div> 
    </form> 
</body> 

代码背后:与更新面板)

protected void ButtonShow_Click(object sender, EventArgs e) 
    { 
     //Show ModalPopup    

     mpeThePopup.Show(); 
    } 
    protected void ButtonClose_Click(object sender, EventArgs e) 
    { 
     //Hide ModalPopup 

     mpeThePopup.Hide(); 
    } 
1

使用,ModalPopupExtender1.Show(以避免整页刷新。这对我来说非常合适。