Close Child Window and Refresh Parent Window in JavaScript
Reload Parent Window on Popup Close
In this blog post, I will demonstrate how to refresh parent page on close of popup jquery in asp.net web application. Find the javascript code snippet below:-
![]() |
reload parent window on popup close |
Step 1: Add a new web form in your web application named parent.aspx and write the following java script function in source.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Parent Window</title>
<script type="text/javascript">
function OpenChildWindow() {
// To open a new browser window, use the window.open() method.
window.open('ChildPage.aspx', null, 'height=300, width=300, status=yes, toolbar=no, menubar=no, location=center, scrollbar=no');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<p>
Click on button to open new window</p>
<asp:Label ID="lbltext" runat="server" />
<asp:Button ID="btnClick" runat="server" Text="Open Child Window"OnClientClick="OpenChildWindow()" />
</div>
</form>
</body>
</html>
Code Behind
Step 2: Secondly add another new web form named Child.aspx and add the following code:
protected void Page_Load(object sender, EventArgs e)
{
// To Display Current Date:
lbltext.Text = DateTime.Now.ToString();
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Child Form</title>
<script type="text/javascript">
function closechildwindow() {
window.opener.document.location.href = 'parent.aspx';
window.close();
}
</script>
</head>
<body onunload="closechildwindow()">
<form id="form1" runat="server">
<div>
<p>
Now close the child window and notice that parent page get changed</p>
</div>
</form>
</body>
</html>
Close Child Window and Refresh Parent Window in JavaScript
Reviewed by Ravi Kumar
on
11:40 AM
Rating:

Thanks
ReplyDelete