Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close Modal popup Extender from Server side

How to close Modal Popup Extender from server side code on click on close link inside the popup?

like image 232
karthik k Avatar asked Mar 25 '10 05:03

karthik k


People also ask

How to close ModalPopupExtender on button click in ASP net?

Solution 2. Ajax modal popup closes if any controls present on it causes a postback. use OKControlID and CancelControlID properties of the modal popup and assign your OK and cancel button ID's for these properties respectively.

What is modal popup extender in asp net?

The ModalPopup extender allows a page to display content to the user in a "modal" manner which prevents the user from interacting with the rest of the page. The modal content can be any hierarchy of controls and is displayed above a background that can have a custom style applied to it.


2 Answers

there is a property in extender for closing popup " CancelControlID" give button id in it and popup will close,if you want to close popup from server side mean from code behind then there is extender property hide(),in button code behind body write id of popup and enter "." after that you get all properties of popup in those property you get hide property.use it hopefully you will get the solution

example

private void btnSubmit_Click(object sender, EventArgs e)
    {
      modelpopupextender.hide();

    }
like image 132
Emaad Ali Avatar answered Oct 15 '22 12:10

Emaad Ali


Answering this question might not be useful to the person who posted it but it might be useful to others.

The following needs to be done to close the modal popup from server side.

Instead of giving the close button id to "CancelControlID" of the modalpopupextender, create a dummy hiddenfield and give this id to "CancelControlID" of the modalpopupextender.

for example

<pre>
<asp:HiddenField ID="hidForModel" runat="server" />;
/*Are you sure you want to know the answer? */
    <asp:Button ID="btnYes" runat="server" Text="Yes!" onclick="btnYes_Click" />;
    <br />;
    <asp:Panel ID="pnlModal" runat="server" CssClass="modalPopup" Style="display: none;">
        <asp:Panel ID="pnlControls" runat="server" CssClass="insideModalPopup></asp:Panel>
        <br />
        <asp:Button ID="btnClose" runat="server" Text="Close" onclick="btnClose_Click" />
    </asp:Panel>
        <cc1:ModalPopupExtender TargetControlID="hidForModel" ID="pnlModal_ModalPopupExtender"
        runat="server" DynamicServicePath="" Enabled="True" BackgroundCssClass="modalBackground"
        PopupControlID="pnlModal" CancelControlID="hidForModel" DropShadow="true">
        </cc1:ModalPopupExtender>
</pre>

Here i have given both TargetControlID and CancelControlID as hidForModel as I want to show as well as hide the modal popup from code-behind.

In Code-Behind

<pre>

        protected void btnYes_Click(object sender, EventArgs e)
        {
            pnlModal_ModalPopupExtender.Show();

            TextBox txt = new TextBox();
            txt.Text = "aaa";
            pnlControls.Controls.Add(txt);
        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            pnlModal_ModalPopupExtender.Hide();
        }
</pre>

Here I have made the modal popup seen and added a textbox from code-behind on click of yes button and hidden the modal popup on click of Close button.

like image 45
samar Avatar answered Oct 15 '22 12:10

samar