Refresh the Parent Window when close the Popup window using JQuery
Recently, I saw in no.of posts everybody asking to refresh the parent window after closing the child window. In this article I'm trying to explain how to refresh the parent window after closing the popup window using Jquery.
Refresh the Parent Window when close the Popup window
Description :
Recently, I saw in no.of posts everybody asking to refresh the parent window after closing the child window. In this article I'm trying to explain how to refresh the parent window after closing the popup window using Jquery. Jquery Script :
<script type="text/javascript" language="javascript">
function RefreshPopup(page) {
var height = $(window).height();
var weight = $(window).width();
if (page != null) {
var $dialog = $('<div id="dialog"></div>')
.html('<iframe id="ifModal" style="border: 0px; overflow: scroll;" src="' + page + '" width="100%" height="100%"></iframe>')
.dialog({
autoOpen: false,
modal: true,
height: height,
width: weight,
close: function (event, ui) {
location.href = location.href;
}
});
win = $dialog.dialog('open');
$(win).load(function () {
var submit = $("#btnSubmit");
$(this).contents().find(submit).attr('disabled', 'disabled');
});
}
}
</script>
Source Code :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PopUp.aspx.cs" Inherits="ScorpCLM_UI.PopUp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui.js" type="text/javascript"></script>
<script src="Scripts/scorp.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
function RefreshPopup(page) {
var height = $(window).height();
var weight = $(window).width();
if (page != null) {
var $dialog = $('<div id="dialog"></div>')
.html('<iframe id="ifModal" style="border: 0px; overflow: scroll;" src="' + page + '" width="100%" height="100%"></iframe>')
.dialog({
autoOpen: false,
modal: true,
height: height,
width: weight,
close: function (event, ui) {
location.href = location.href;
}
});
win = $dialog.dialog('open');
$(win).load(function () {
var submit = $("#btnSubmit");
$(this).contents().find(submit).attr('disabled', 'disabled');
});
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvRefresh" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None"
BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" OnRowCommand="gvpopup_OnRowCommand">
<FooterStyle BackColor="gray" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
<Columns>
<asp:TemplateField HeaderText="Dept Name">
<ItemTemplate>
<asp:LinkButton ID="lnkDeptName" runat="server" CommandName="Refresh_ParentWindow" Text='<%#DataBinder.Eval(Container.DataItem,"DeptName") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Code Behind :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace ScorpCLM_UI
{
public partial class ParentWindow: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("DeptName");
DataRow dr = dt.NewRow();
dr["DeptName"] = "IT";
DataRow dr1 = dt.NewRow();
dr1["DeptName"] = "EC";
DataRow dr2 = dt.NewRow();
dr2["DeptName"] = "MECH";
dt.Rows.Add(dr);
dt.Rows.Add(dr1);
dt.Rows.Add(dr2);
gvRefresh.DataSource = dt;
gvRefresh.DataBind();
}
}
protected void gvpopup_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Refresh_ParentWindow")
{
string URL = "CheckedGrid.aspx";
ScriptManager.RegisterStartupScript(this, this.GetType(), "myalert", "javascript:openModalPopup('" + URL + "');", true);
}
}
}
}
Conclusion:
This article will help you those who are looking for the same..