简体   繁体   中英

Another modal popup extender question

I am trying to get a modal popup to work, it needs to be triggered in the Code behind.

 <asp:Button ID="btnModalPopUp" runat="server" Text="Button" Style="display: none" />
<asp:Panel ID="pnlModalPopup" runat="server" CssClass="modalPopup" Style="display: none"
    Width="233px">
    <div id="Div1" runat="server" cssclass="title">
        Modal text here.
        <asp:TextBox ID="txtEditComments" runat="server"></asp:TextBox>
    </div>
</asp:Panel>
<cc1:ModalPopupExtender ID="modalMessage" runat="server" TargetControlID="btnModalPopUp"
    PopupControlID="pnlModalPopup" BackgroundCssClass="modalBackground"         DropShadow="true"/>

Code behind:

protected void Page_Load(object sender, EventArgs e)
{
    modalMessage.Show();
}

Even though it hits the "modalMessage.Show();" code it doesn't show the modal panel.

Two solutions:

The first solution:

Remove Style="display:none" from the pnlModalPopup .

The first solution is will cause the popup to "flash" on the screen when the page first loads, and then quickly disappear.

The second solution:

protected void Page_Load(object sender, EventArgs e)
{
    pnlModalPopup.Style["display"] = "block";
    modalMessage.Show();
}

Recommendation: I would recommend using the second solution, that way the modal popup doesn't flicker and then disappear.

Edit: I just tested your code:

I just tested your code in a simple page that contained only the code that you provided... It worked like expected .

Check the following:

  1. Is your modal popup is defined in an UpdatePanel that is conditionally updated?
  2. Check to make sure that the modal popup isn't defined in a Panel that has it's visibility set to false.
  3. If that doesn't work, then check if the modal popup is actually in the source code of the rendered web page.

Listen to Chris's comment as it is needed:

display:none is cosmetically needed, otherwise the popup will display when the page is loading, then will quickly disappear while the ModalPopupExtender kicks in and hides it.

We had to make ours show like this:

  pnlModalPopup.Visible = true;           
  modalMessage.Show();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM