![]() |
Web Development »
ASP.NET »
General
Intermediate
License: The Code Project Open License (CPOL)
Passing Data and objects between parent and child web formsBy Mohammad Al HossPassing Data and objects between parent and child web forms |
HTML, .NET (.NET 2.0), ASP.NET, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
This article will show how to send simple data and Data Objects such as Datatable and DataSet
between two web forms. This can be used to perform a certain kind of search or calculations
in a separate from the post the results back to the patent from.
Parent Page:
</html> <head runat="server"> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> function GetValueFromChild(myVal) { document.getElementById('mytxt').value = myVal; } function OpenWindow() { window.open("chiled.aspx", "newwin", "height=250,width=250,toolbar=no,scrollbars="+scroll+",menubar=no"); } </script> </head> <body> <form id="form1" runat="server"> <div> <input id="mytxt" type="text" /> <input type ="button" value="chiled window" onclick="OpenWindow()" /> </div> </form> </body> </html>
Child Page
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> function SendValueToParent() { var myVal = document.getElementById('mytxt').value; //window.opener.GetValueFromChild(myVal); //window.close(); //return false; window.opener.form1.mytxt.value = myVal; window.close(); return false; //window.opener.form1.submit(); } </script> </head> <body> <form id="form1" runat="server"> <div> <input id="mytxt" type="text" /> <input id="btn1" type="button" value="Send Value to Parent" onclick="javascript:return SendValueToParent();" /> </div> </form> </body> </html>
Parent Page
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <script type ="text/javascript"> function openchiled() { window.open("DataTable.aspx", "newwin", "height=250,width=250,toolbar=no,scrollbars="+scroll+",menubar=no"); return false; } </script> <title>Parent Data Table</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> <a href="#" onclick="openchiled()" >Open Child dataTable</a> </div> </form> </body> </html>
Child page
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:LinkButton ID="LinkButton1" Text="Send DataTable" runat="server" OnClick="LinkButton1_Click"></asp:LinkButton> </div> </form> </body> </html>
child C# code
protected void LinkButton1_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add("FName", typeof(System.String)); dt.Columns.Add("LName", typeof(System.String)); System.Data.DataRow DR = dt.NewRow(); DR["FName"] = "First Name"; DR["LName"] = "Last Name"; dt.Rows.Add(DR); dt.AcceptChanges(); Session["DT"] = dt; Response.Write("<script type =text/javascript> window.opener.form1.submit(); window.close(); </script>"); }
I hope that you will find it useful
Development to me is a pleasure more than a job
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 23 Aug 2008 Editor: |
Copyright 2008 by Mohammad Al Hoss Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |