CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Refresh or Submit the Parent page from PopUp Window Using Javascript in ASP.Net
Submitted By Bala Murugan
On 5/25/2010 8:23:59 AM
Tags: ASP.Net,CodeDigest,Javascript  

Refresh or Submit the Parent page from PopUp Window Using Javascript

Sometimes, we may get a scenario where we need to refresh or submit the parent aspx page from a child or popup window using javascript.


For example, selecting a employee name from a person picker
Pop-up window which in turn should populate the selected employee name to a parent page element  and submit the page for some processing on server.


The below little code snippet will populate the value typed in a textbox(txtEmployee) from popup(SearchEmployees.aspx) into parent page textbox(txtName) and submit the page. By this way, the parent page can do some processing on the server based the value selected on pop-up(SearchEmployees.aspx).

 

ParentPage.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:Button ID="btnSelect" OnClientClick="javascript: window.open("SearchEmployees.aspx", "Employees", "width=250,height=250");" runat="server" Text="Select Employee" />
</form>
</body>
</html>

 

SearchEmployees.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function SubmitToParent() {
window.opener.document.forms[0].txtName.value = document.getElementById("txtEmployee").value;
window.opener.document.forms[0].submit();
window.close();
}

</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtEmployee" runat="server"></asp:TextBox>
<asp:Button ID="btnGo" OnClientClick="SubmitToParent()" runat="server" Text="Go" />
</form>
</body>
</html>

 

In the above code, i have just populated the value typed in txtEmployee to parent page for easy understanding. In real world application, it can be populated in different way according to your need. Like from a search results, etc.

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..