ModelPopupExtender没有显示在pageLoad后面的代码中

时间:2021-07-05 04:00:19

I need to display popup when page loads. I have used ModelPopupExtender. It does shows on it's TargetControlID click but not showing on page load from code behind. I have check many solutions on stack but none of them are working for me.

我需要在页面加载时显示弹出窗口。我使用过ModelPopupExtender。它确实显示了它的TargetControlID点击,但没有显示在代码隐藏的页面加载上。我已经在堆栈上检查了很多解决方案,但它们都没有为我工作。

protected void Page_Load(object sender, System.EventArgs e)
{
    this.mpOTP.Show();
}

 <asp:Button ID="activateMpOtp" runat="server" Text="Open" ClientIDMode="Static"/>
    <asp:ModalPopupExtender ID="mpOTP" runat="server" BackgroundCssClass="popup-overlay" PopupControlID="pnlOTP" CancelControlID="closeOTP" TargetControlID="activateMpOtp"></asp:ModalPopupExtender>

    <asp:Panel ID="pnlOTP" runat="server" CssClass="popup-dialogue">
    </asp:Panel>

Getting this error in console ModelPopupExtender没有显示在pageLoad后面的代码中

在控制台中获取此错误

1 个解决方案

#1


0  

Your markup is not correct.

您的标记不正确。

First of all, you need to register AjaxControlToolKit controls by using the following directive at the top of your page markup, just after the page directive.

首先,您需要在页面标记的顶部使用以下指令注册AjaxControlToolKit控件,就在页面指令之后。

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act %>

Then, your markup should look like the following. Problems with your markup are listed below.

然后,您的标记应如下所示。下面列出了您的标记问题。

  • You have not included markup for the cancel button
  • 您尚未为取消按钮添加标记

  • and also your control prefix is wrong since it should not be asp which is the prefix is for ASP.Net Microsoft controls and not for AJAXControlToolKit (NOTE: you give this prefix in your register directive for AjaxControl,Toolkit, which is act in code sample given, but you could give any prefix and use it for modalpopuextender)
  • 并且您的控件前缀是错误的,因为它不应该是asp,这是ASP.Net Microsoft控件的前缀,而不是AJAXControlToolKit(注意:您在您的register指令中为AjaxControl,Toolkit提供此前缀,这是代码示例中的行为给出,但你可以给任何前缀并将其用于modalpopuextender)

Correct markup for ModalPopupExtender

ModalPopupExtender的正确标记

<asp:Button ID="activateMpOtp" runat="server" Text="Open" ClientIDMode="Static"/>
<act:ModalPopupExtender ID="mpOTP" runat="server" BackgroundCssClass="popup-overlay"
         PopupControlID="pnlOTP" CancelControlID="closeOTP"
         TargetControlID="activateMpOtp"></act:ModalPopupExtender>

<asp:Panel ID="pnlOTP" runat="server" CssClass="popup-dialogue">
  <div class="header">
    Modal Popup
  </div>
  <div class="body">
    Your content goes here
    <br />
    <asp:Button ID="closeOTP" runat="server" Text="Close" />
 </div>
</asp:Panel>

#1


0  

Your markup is not correct.

您的标记不正确。

First of all, you need to register AjaxControlToolKit controls by using the following directive at the top of your page markup, just after the page directive.

首先,您需要在页面标记的顶部使用以下指令注册AjaxControlToolKit控件,就在页面指令之后。

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act %>

Then, your markup should look like the following. Problems with your markup are listed below.

然后,您的标记应如下所示。下面列出了您的标记问题。

  • You have not included markup for the cancel button
  • 您尚未为取消按钮添加标记

  • and also your control prefix is wrong since it should not be asp which is the prefix is for ASP.Net Microsoft controls and not for AJAXControlToolKit (NOTE: you give this prefix in your register directive for AjaxControl,Toolkit, which is act in code sample given, but you could give any prefix and use it for modalpopuextender)
  • 并且您的控件前缀是错误的,因为它不应该是asp,这是ASP.Net Microsoft控件的前缀,而不是AJAXControlToolKit(注意:您在您的register指令中为AjaxControl,Toolkit提供此前缀,这是代码示例中的行为给出,但你可以给任何前缀并将其用于modalpopuextender)

Correct markup for ModalPopupExtender

ModalPopupExtender的正确标记

<asp:Button ID="activateMpOtp" runat="server" Text="Open" ClientIDMode="Static"/>
<act:ModalPopupExtender ID="mpOTP" runat="server" BackgroundCssClass="popup-overlay"
         PopupControlID="pnlOTP" CancelControlID="closeOTP"
         TargetControlID="activateMpOtp"></act:ModalPopupExtender>

<asp:Panel ID="pnlOTP" runat="server" CssClass="popup-dialogue">
  <div class="header">
    Modal Popup
  </div>
  <div class="body">
    Your content goes here
    <br />
    <asp:Button ID="closeOTP" runat="server" Text="Close" />
 </div>
</asp:Panel>