Powered by Blogger.

Friday, February 14, 2014

ModalPopupExtender background css not coming when showing from code behind in asp.net



Sometimes while calling the ModalPopupExtender the background css class will not appear, In this post we will discuss about this solution.

Also you can check out my previous posts on:

- Add Primary Key Constraint to existing table in sql server 2008

- Show confirmation message in gridview for delete in Asp.net

- How to use a Thread Pool class in C#.Net?

In my requirement I was showing the modalpopup from the code behind file and for this, I took a button and made that as Visible="false", check below:

<asp:Button ID="btnForAjax" runat="server" Text="" Visible="false" />
        <ajaxtoolkit:modalpopupextender id="ModalPopupExtender1" runat="server" backgroundcssclass="modalBackground"
            popupcontrolid="pnlPopupMsg" targetcontrolid="btnForAjax">
                    </ajaxtoolkit:modalpopupextender>

Problem:
Here the problem was I was setting Visible="false" for btnForAjax.

Solution:
The solution is we should remove the Visible="false" and we can put Style="display: none" like below:

<asp:Button ID="Button1" runat="server" Text="" Style="display: none"/>

You can check:
- Show ModalPopupExtender in code behind in Ajax in Asp.Net

- ModalPopupExtender example in Ajax in Asp.Net

Now it should work fine.