Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

Okay, I was getting lot of emails about how to pass the data from the child window to the parent window. In the code below I pass the DataTable from the child window to the parent window. The child window has a datagrid and you select the items from the datagrid and those items are passed back to the parent window.

Parent Window:

protected void Page_Load(object sender, EventArgs e)
    {
        
        
if (Session["SelectedItems"] != null)
        {
            GridView1.DataSource = (DataTable)Session["SelectedItems"];
            GridView1.DataBind(); 
        }
    }

Child Window:

protected void Button1_Click(object sender, EventArgs e)
    {
                
            
// Make a datatable which will hold the values 
        
DataTable myTable = new DataTable();
        myTable.Columns.Add("CategoryID");
        myTable.Columns.Add("CategoryName");

        DataRow myRow = 
null

        
foreach (GridViewRow row in gvChild.Rows)
        {
            
bool result = ((CheckBox) row.FindControl("CheckBox1")).Checked;
            
if (result)
            {
                myRow = myTable.NewRow();
                myRow["CategoryID"] = row.Cells[0].Text;
                myRow["CategoryName"] = row.Cells[1].Text;
                myTable.Rows.Add(myRow); 
            }
        }        
        
        Session["SelectedItems"] = myTable;
        Button1.OnClientClick = "PassValues()";         
        
    }

And the javascript function PassValues():

<script language="javascript" type="text/javascript">

    function PassValues() 
    { 
    window.opener.document.forms(0).submit();
    self.close();
     
    }

</script>

There is however a problem with the above code. Which is that you need to press the button in the child window twice to get the window close and display the values on the parent window. If you figure out the solution then let me know :)

 

powered by IMHO

 

Posted on Wednesday, November 16, 2005 10:53 AM | Back to top


Comments on this post: Passing Data from the Child Window to the Parent

# re: Passing Data from the Child Window to the Parent
Requesting Gravatar...
Okay, I got it working. Simply call PassValues in the onunload event of the child page. :)
Left by Azamsharp on Nov 16, 2005 11:32 AM

# re: Passing Data from the Child Window to the Parent
Requesting Gravatar...
It finds very helpful to me in development,but i want to know how to make a form parent or child? Is a web form parent by default?
Left by Sulaiman vp on Dec 08, 2005 3:47 AM

# re: Passing Data from the Child Window to the Parent
Requesting Gravatar...
plz send me as early as possible
Left by harish kumar on Feb 15, 2006 7:28 PM

# re: Passing Data from the Child Window to the Parent
Requesting Gravatar...
In child window
function settingValue(accNoValue,accNameValue)
{
alert("within lookup");
alert(accNameValue.value);
alert(accNoValue.value);
parent.document.forms['readingFromXLSForm'].contactName.value = accNameValue.value;
parent.document.forms['readingFromXLSForm'].contactNo.value = accNoValue.value;
alert("finish");
self.close();
}
Left by Arpita kanon on Jun 16, 2006 2:39 AM

# re: Passing Data from the Child Window to the Parent
Requesting Gravatar...
Fine.its working.Thanx.
Left by Angai on Feb 14, 2008 10:10 PM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net