ASP.NET - submit and close modal popup window - Asked By Anandh Ramanujam on 10-Feb-12 09:27 AM


Iam opening a modal popup window from an aspx page.

in modal popup, if i click server side button, perform some db changes and should close the window...

Here the code i have written:

in button_click event:

performing some db operations....
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "javascript:window.close()", true);

But it doesnt work well. What happens is, when i click the button, it opens the same page in another new window, and prompt us 'are u want to close this window yes/no'. and the modal popup remains still.

Can u pls help me in this regard


Suchit shah replied to Anandh Ramanujam on 10-Feb-12 09:53 AM
Try it on this way
protected void btn_save(object sender, eventargs e)
// Here you can do your DB operation and now follow below way to close itt

   string scriptKey = "RefreshParentScript";
   string javaScript = "refreshParent();";
   ClientScript.RegisterStartupScript(this.GetType(), scriptKey, javaScript, true);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "javascript:window.close()", true); 

Anandh Ramanujam replied to Suchit shah on 10-Feb-12 09:59 AM
where is this method refreshParent() defined ????
dipa ahuja replied to Anandh Ramanujam on 10-Feb-12 10:29 AM
try this

<a href="javascript:window.opener='x';window.close();">Close me</a>
kalpana aparnathi replied to Anandh Ramanujam on 10-Feb-12 01:10 PM

The ModalPopupExtender has the ‘Show()’ function to show the popup panel both at client side and the server side.
Each AjaxControlToolkit extender can has its own BehaviorID, we can use either the ID or the BehaviorID to find the AjaxExtender by writing “$find(‘ID’)” or “$find(‘BehaviorID’)” in javascript.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase", Justification = "Following ASP.NET AJAX pattern")]
public string BehaviorID
string id = GetPropertyValue("BehaviorID", "");
return (string.IsNullOrEmpty(id) ? ClientID : id);
SetPropertyValue("BehaviorID", value);
Anandh Ramanujam replied to Anandh Ramanujam on 10-Feb-12 01:45 PM
I got the solution, by specifying <base target="_self"></base> attribute in <head> section. Now, its working fine.

Thanks for all ur support.