Refreshing Parent Window - ASP.Net and JavaScript
After having searched for this solution since a long time, i finally came across something that is worth posting in here before I tend to forget it again.
Well when using asp.net to develop web/intranet based applications, often we come across a situation where we have a list of records and clicking on one record gives us the detail of that record in another window. The normal flow requires that when we edit the record and close the detail window, we would want to refresh the parent window such that the changes we made appear in the list. I thought that this was practically impossible since its normally difficult to capture window closing events on web browsers. But here's a tricky solution that works.
- In the list page, when clicking on a record, you ought to have a javascript code that goes something like:
newwindow = window.open("page path and window height etc...");
newwindow.focus();
note that you may use Page.RegisterStartupScript or Response.Write to output the javascript code onto the page. - On the list page itself, in it HTML view have this added:
function Refresh()
{
__doPostBack('','');
} - On the child window(details one) have this code added in the HTML view:
function RefreshParent()
{
if ((parent.opener!=null) && (parent.opener.document.title == "List Customer"))
{
parent.opener.Refresh();
}
}
window.onunload = function(){if(self.screenTop>9000)RefreshParent()}
note that you need to change the "List Customer" to make sure it matches the Title of your list page.
So there you go, a work around solution for this. It works for me, no reason why it shouldn't work for others :)
Happy Programming!!!
0 Comments:
Post a Comment
<< Home