调用Alert JavaScript函数时出现ASP.NET ModalPopupExtender

时间:2012-10-10 07:23:17

标签: asp.net asp.net-ajax ajaxcontroltoolkit modalpopupextender

我正面临来自ASP.NET Ajax Controls Toolkit ModalPopupExtender的错误行为,当我从服务器端调用Alert() JavaScript函数时,模态出现在后台。我不知道为什么会这样。

这是代码:

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>

1 个答案:

答案 0 :(得分:6)

问题是由ModalPopupExtender的工作方式引起的。它发出的JavaScript会隐藏Panel

现在您将alert()调用注册为启动脚本,只要用户不退出警报窗口,这将保持运行ModalPopupExtender脚本。最简单的解决方法是在display:none上设置Panel,这样就不需要脚本来隐藏它了:

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