Refreshing a parent page from a
popup ASP.Net page
There are situations where we will be
required to populate the information’s entered on the popups to the parent page and
refresh the parent page so that it can be accessed in the server side. The below
example will help us in achieving it.
The below example will populate the
entered name in the child.aspx(popup) to the parent(Parent.aspx) and submit the
page to the server.
Parent.aspx
<script language="javascript">
function
OpenWindow(strChildPageUrl)
{
var testwindow =
window.open(strChildPageUrl,"Child","width=400px,height=400px,top=0,left=0,scrollbars=1");
}
</script>
<form id="form1" runat="server"
>
<div>
<asp:TextBox ID="txtName"
runat="server"></asp:TextBox>
<input type="button" ID="Button1"
value="Enter Name" OnClick="OpenWindow('Child.aspx')" />
</div>
</form>
Child.aspx
<script
language="javascript">
function SubmitToParent()
{
window.opener.document.forms[0].txtName.value =
document.getElementById('txtChildName').value;
window.opener.document.forms[0].submit();
self.close();
}
</script>
<form id="form1" runat="server”
>
<div>
<asp:TextBox ID="txtChildName"
runat="server"></asp:TextBox>
<input type="button" ID="Button1"
value="Submit to Parent" OnClick="SubmitToParent()" />
</div>
</form>
Now, in the parent page we can access
the submitted name in the codebehind during the refresh.
protected void Page_Load(object sender,
EventArgs e)
{
if(txtName.Text != "")
Response.Write(txtName.Text);
}
|