I would like to close the browser window when an ASP.NET operation has succeeded. The code below is triggered by a button that resides in an Ajax UpdatePanel.
Page.ClientScript.RegisterClientScriptBlock(typeof(LeaveApproval), "ShowSuccess", "<script language=javascript>window.opener=self; self.close();</script>");
However, this code does not seem to have any effect. The window is not closed. When I enter the javascript into the URL bar of my browser it works fine, so I’m guessing this has something to do with using the ClientScriptManager together with Ajax.
Any idea what I am doing wrong?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
This link by Scott Klueppel helped me solve the problem…
Rather use…
ScriptManager.RegisterStartupScript
instead of
Page.ClientScript.RegisterClientScriptBlock.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0