Summary:
In this article, I'm going to explain how to refresh a parent page from a child page using the new API of ASP.NET 2.0 and JavaScript language. Sometimes, it is required to provide a popup windows showing detail information of one business entity among several ones residing in a parent page for example inside a Repeater control, and when the former business entity's properties change, the content in the parent page must be updated.
Solution.
You create a parent page with Repeater control where it is presented several business entities in a resumed way, and a reference to a child page showing detailed information of each one. You can do that through JavaScript code and generating the proper reference using <a> tag. It is supposed that you define DataSet and DataTable objects for some business entity's schemas residing in a RDBMS which has a property named
<a href="javascript:OpenWindow('childpage.aspx?id=<%# DataBinder.Eval(Container.DataItem,"Id")%>')>Click for detail information</a>
<script language="javascript" type="text/javascript">
function OpenWindow(strChildPageUrl)
{
window.open (strChildPageUrl, 'New Page','width=600px,height=800px,top=0,left=0,scrollbars=1');
}
</script>
The OpenWindow function is triggered when the user click on the reference which causes to open a new popup windows.
Refreshing the parent page.
If you change something in the child windows, the changes will not be reflected in the parent windows until it's refreshed. The user can click on the "Refresh" button in the web browser but it's not a good approach. One simple solution is to add the following client-side code:
window.opener.document.forms[0].submit();
The only drawback is that if you have some Validators controls on the page, the parent page is not submitted.
In ASP.NET 2.0 you can add this client-side code through the Page.ClientScript object instance of the class ClientScriptManager. So, in the child page's Load event handler write the following server-side code.
protected void Page_Load(object sender, EventArgs e)
{
const string cRefreshParent = "<script language='javascript'>" +
" window.opener.document.forms(0).submit();" + "</script>";
const string cRefreshParentKey = "RefreshParentKey";
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(cRefreshParentKey))
{
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
cRefreshParentKey, cRefreshParent);
}
}
I guess that this solution is simple but very useful if you want to create Web applications by the popup windows.

Tom JacksoneditedPosted Aug 7, 2010, 4:20 PMEdited Aug 7, 2010, 4:26 PM
If you add the code in this article to the parent Page_Load, it puts this line at the bottom of the page <script language='javascript'> window.opener.document.forms(0).submit(); and gives this error: Microsoft JScript runtime error: 'window.opener.document' is null or not an object If you add this to the child Page_Load, it puts the same line at the bottom of the page and you get this error: Microsoft JScript runtime error: Object doesn't support this property or method Was this actually tested by anyone? I have page A with a GridView. It has buttons for each row. Those buttons open page B with different passed-in URL parameters. Page B has a submit button. When that button is clicked, it needs to close page B and show the result (a deleted file being removed from the list in the GridView) on page A, which would show with a refresh. This should be simple - I've seen countless pages on the web that do the same thing, but nothing I've seen in C# works so far, and you can't call JavaScript on page A (like a window.reload()) to run just from page B closing, can you? Would love to see this work. -Tom
mugu ramPosted May 5, 2009, 3:06 AM
Please any one let me know if you find any solution for my question. please....... I have two child window and i'm refreshing the first child with the second child and at the same time PARENT page will be refreshed when first child got refreshed. My parent page carries huge amount of data in it, hence the child's loses its focus and got focused to parent page....... I tried this using javascripts "window.opener.document.location.reload()"......please let me know if anyone find a solution for this.......
rinkeshshahPosted Aug 23, 2008, 5:55 PM
window.opener.reload() OR window.opener.refresh() both sould work that's not create problem with use of Validation control. --Rinkesh
rinkeshshahPosted Aug 23, 2008, 5:55 PM
window.opener.reload() OR window.opener.refresh() both sould work that's not create problem with use of Validation control. --Rinkesh
rinkeshshahPosted Aug 23, 2008, 5:54 PM
window.opener.reload() OR window.opener.refresh() both sould work that's not create problem with use of Validation control. --Rinkesh