This is a migrated thread and some comments may be shown as answers.

Close the Popup After Update

2 Answers 73 Views
Window
This is a migrated thread and some comments may be shown as answers.
Vuyiswa
Top achievements
Rank 2
Vuyiswa asked on 22 Feb 2012, 11:05 PM
Good Morning All 


I am Opening a Page as a Popup i am using Telerik WIndow which has similar functionality when opening a Popup like this 

 
function OpenPopUp(val_real, vis) {
          var myWidth = 0, myHeight = 0;
          if (typeof (window.innerWidth) == 'number') {
              //Non-IE
              myWidth = window.innerWidth;
              myHeight = window.innerHeight;
          } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
              //IE 6+ in 'standards compliant mode'
              myWidth = document.documentElement.clientWidth;
              myHeight = document.documentElement.clientHeight;
          } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
              //IE 4 compatible
              myWidth = document.body.clientWidth;
              myHeight = document.body.clientHeight;
          }
 
 
          myWidth = myWidth / 2 - 150;
          myHeight = myHeight / 2 - 50;
          window.open('MyPage.aspx?Val=' + val_read, 'width=700,height=160,top=' + myHeight + ',left=' + myWidth)
          return false;
 
 
      }

this "myPage.aspx" page has a button that person some updates to the Database on the server side. This is opened as a popup and there is a grid below , so what i want to do after the Update to the Database has happened , i want to refresh the Grid, i have this code 
 
//This code is used to provide a reference to the radwindow "wrapper"
     function GetRadWindow() {
         var oWindow = null;
         if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
         else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz az well)            
         return oWindow;
     }
 
 
     function CloseOnReload() {
         //alert("Dialog is about to close itself");
         GetRadWindow().close();
         RefreshParentPage();
     }
 
 
     function RefreshParentPage() {
         //alert("Dialog is about to reload parent page");
         GetRadWindow().BrowserWindow.location.reload();
     }
 
 
     function RedirectParentPage(newUrl) {
         alert("Dialog is about to redirect parent page to " + newUrl);
         GetRadWindow().BrowserWindow.document.location.href = newUrl;
     }
 
 
     function CallFunctionOnParentPage(fnName) {
         alert("Calling the function " + fnName + " defined on the parent page");
         var oWindow = GetRadWindow();
         if (oWindow.BrowserWindow[fnName] && typeof (oWindow.BrowserWindow[fnName]) == "function") {
             oWindow.BrowserWindow[fnName](oWindow);
         }
     }
 
 
     function RefreshParentPageWithoutWarning() {
         GetRadWindow().BrowserWindow.document.forms[0].submit();
     }


and on the server side i have this 


Response.Write("<Script>return RefreshParentPageWithoutWarning();</script>")
 

or 

SavetoDB(Values)
ScriptManager.RegisterStartupScript(Page, Me.GetType(), "", "RefreshParentPageWithoutWarning()", True)
 


My problem here is that it Refresh the page before it does a Database Update, and if it refreshes the page , the Database update ends up not being done. 


Thanks
     

2 Answers, 1 is accepted

Sort by
0
rdmptn
Top achievements
Rank 1
answered on 24 Feb 2012, 04:48 PM
The scripts registered via the script manager or Response.Write() are executed only when they are received on the client. This happens after all server-side code has finished processing so the final response can be prepared and sent to the client. I am attaching here an image that illustrates the lifecycle of an aspx page. The above means that if a database insert is not performed the most likely reason for this is in its server code, not in the page reload. I also see that you are not opening a RadWindow, but a regular browser window with your first JavaScript snippet, so the JavaScript inside the second page would hardly work. Nevertheless, if you are convinced the page reload is the cause you can delay it with setTimeout() method (often 0ms suffice just to let the browser finish work, but you can give it several seconds if you like) or you can utilize the Sys.Appilication.Load event when injecting the script to have the content page fully loaded before refreshing.
0
Vuyiswa
Top achievements
Rank 2
answered on 24 Feb 2012, 07:12 PM
hi 

i have resolved the issue  like this 

 
Dim page As Page = HttpContext.Current.Handler
ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "CloseOnReload();",
Tags
Window
Asked by
Vuyiswa
Top achievements
Rank 2
Answers by
rdmptn
Top achievements
Rank 1
Vuyiswa
Top achievements
Rank 2
Share this question
or