views:

354

answers:

2

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.

+2  A: 

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.
Chris
These two solutions didn't work. Thanks anyway.
Adam Smith
Are there any other references in your code where you set the visibility of the `pnlModalPopup` (Either through the style tag, or the visible property)?
Chris
CSS:.modalBackground { background-color:Gray; filter:alpha(opacity=70); opacity:0.7; }.modalPopup{ background-color:#ffffff; padding:3px;}This is the only styling I do with those controls.
Adam Smith
I to can get it to work in a standard aspx page with no masterpages or extra stuff.To answer your questions:1. No, it isn't in a update panel.2. No, it is not in another panel that is hidden, it is however in a masterpage.3. Yes, it seems to be all there in the source code.
Adam Smith
@Adam: Is the Page_Load you are using in the master page or the specific page of concern?
Chris
I just added the `modalMessage` to a `Master` page in my test app, and it still works fine. I would try and track down and evaluate all references to `modalMessage` and `pnlModalPopup`
Chris
Also, what css are you using for the "title" class?
Chris
Another thought, is your logic for hiding the modalMessage being triggered and executed somehow?
Chris
Still couldn't get it to 100%. Not sure what the problem was. Thanks everyone for the help.
Adam Smith
A: 

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();
rick schott
that would only work if they were setting the Visible property to false somewhere in the code behind, because he isn't setting the Visible property in the markup. And if that were the case...he should consider **never setting the `Visible` property in the first place.**
Chris
We don't set the visible property in ours, test it out.
rick schott
If the modal doesn't display, there is more than likely a JavaScript error.
rick schott
If you put a break point there, you will see that `pnlModalPopup.Visible` is true before you set it to true. The statement is redundant and unnecessary *unless* you've set the `Visible` property to false before hand.
Chris
I don't disagree with you, sometimes people don't come clean with their explanations. If it doesn't work while being explicit, he has other issues.
rick schott