4

當我從服務器端調用Alert() JavaScript函數時,我正面臨ASP.NET Ajax控件工具包ModalPopupExtender中的錯誤行爲,模式出現在背後。我不知道爲什麼會發生這種情況。當調用Alert JavaScript函數時出現ASP.NET ModalPopupExtender

這裏是代碼:

VB:

Sub ShowAlert(ByVal message As String) 
    ScriptManager.RegisterStartupScript(Me.UpdatePanel, UpdatePanel.GetType(), "notificationScript", "<script language='JavaScript'> alert('" & message & "'); </script>", False) 
End Sub 

ASPX:

<asp:UpdatePanel ID="UpdatePanel" runat="server"> 
    <ContentTemplate> 
     <asp:Panel ID="pnlPartialInstructions" CssClass="modal" runat="server"> 
     ...... 
     <asp:Panel ID="pnlPrintConfirmation" CssClass="modal" runat="server"> 
      <table class="ui-accordion"> 
       <tr> 
        <td colspan="2"> 
         <asp:Label Text="Do you want to print the receipt?" ID="lblPrintConfirmation" runat="server" 
          meta:resourcekey="lblPrintConfirmationResource1" Font-Bold="True" Font-Names="tahoma" 
          Font-Size="Large" /> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <asp:Button ID="btnConfirmPrint" Text="Yes" CssClass="google-button google-button-blue" 
          runat="server" meta:resourcekey="btnConfirmSaveResource1" Font-Size="Large" /> 
        </td> 
        <td> 
         <asp:Button ID="btnCancelPrint" Text="No" CssClass="google-button google-button-red" 
          runat="server" meta:resourcekey="btnCancelSaveResource1" Font-Size="Large" /> 
        </td> 
       </tr> 
      </table> 
     </asp:Panel> 
     <asp:Button ID="HiddenForModel1" Text="" runat="server" CssClass="hide" CausesValidation="False" /> 
     <ajaxToolkit:ModalPopupExtender ID="pnlPrintConfirmation_ModalPopupExtender" runat="server" DynamicServicePath="" 
      Enabled="True" TargetControlID="HiddenForModel1" PopupControlID="pnlPrintConfirmation" 
      BackgroundCssClass="ModalBackground" DropShadow="True" CancelControlID="btnCancelPrint" 
      RepositionMode="RepositionOnWindowResizeAndScroll"> 
     </ajaxToolkit:ModalPopupExtender> 

     ..... 
     </asp:UpdatePanel> 
    </ContentTemplate> 

回答

6

的問題是順便ModalPopupExtender作品引起的。它發出的JavaScript將隱藏Panel

現在您正在將您的alert()呼叫註冊爲啓動腳本,只要用戶不會退出警報windown,這將保持運行ModalPopupExtender腳本。最簡單的修復方法是在Panel上設置display:none,因此它不需要腳本來隱藏它:

<asp:Panel ID="pnlPrintConfirmation" CssClass="modal" Style="display:none;" runat="server"> 
    ... 
</asp:Panel> 
相關問題