<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d8260084\x26blogName\x3dInspirone\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttps://inspirone.blogspot.com/search\x26blogLocale\x3den_GB\x26v\x3d2\x26homepageUrl\x3dhttp://inspirone.blogspot.com/\x26vt\x3d5304759022731441925', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe", messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER, messageHandlers: { 'blogger-ping': function() {} } }); } }); </script>

Inspirone

"I maintain that Truth is a pathless land, and you cannot approach it by any path whatsoever, by any religion, by any sect. Truth, being limitless, unconditioned, unapproachable by any path whatsoever, cannot be organized; nor should any organization be formed to lead or to coerce people along any particular path. You must climb towards the Truth. It cannot be 'stepped down' or organized for you." - author: Jiddu Krishnamurthi

Monday, August 01, 2005

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.
  1. 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.
  2. On the list page itself, in it HTML view have this added:

    function Refresh()
    {
    __doPostBack('','');
    }
  3. 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!!!