How to close Modal Popup Extender
from server side code on click on close link inside th开发者_如何学Pythone popup?
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();
}
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.
You can use CancelControlID attribute to close the Popup box.
<asp:ModalPopupExtender ID="mpe_login" runat="server"
TargetControlID="btn_login_popup" PopupControlID="panel_login"
BackgroundCssClass="LoginBackground1"
CancelControlID="btn_Cancel" />
精彩评论