Monday, October 1, 2012

ASP.NET - close child window and refresh parent window

Example:1
ASP.NET 2.0
Page.ClientScript.RegisterStartUpScript(this.GetType(),"close","<script language=javascript>window.opener.location.reload(true);self.close();</script>");

Example:2
ASP.NET 1.X
Page.RegisterStartUpScript("close","<script language=javascript>window.opener.location.reload(true);self.close();</script>");
Example:3
Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "&lt;script language=javascript>window.opener.location.reload(true);self.close();</script>");
     }
Example:4
 
protected void btn_submit_Click(object sender, EventArgs e){

string Isok = "";
//*****save data to database code here, if save ok, then set Isok="y", else set Isok="n". ******
if (Isok=="y"){ //close window and refresh parent winsow

Page.ClientScript.RegisterStartUpScript(this.GetType(),"close","<script language=javascript>window.opener.location.reload(true);self.close();</script>");
}


Example:5

window.opener.location.href="parentWindow.aspx"
self.close();
Example:6
<script language="JavaScript">
<!--
function refreshParent() {
  window.opener.location.href = window.opener.location.href;

  if (window.opener.progressWindow)
  
 {
    window.opener.progressWindow.close()
  }
  window.close();
}
//-->
</script>

No comments:

Post a Comment