Click here to Skip to main content
15,912,021 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I have a parent window contains a Textbox and input button controls. And child window contains a Gridview control & Textbox.

I want to pass the value from the child window to parent window whenever I select the record from the gridview of the child window. and child window must be closed after select the record from the gridview control.

In my code I am passing the parameter from parent to child window.

Here is my Code:

Parent Window:

XML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
    <title>Parent Window</title>
    <script type="text/javascript" language="javascript">
    function showChildWin()
    {
       var MyValue=document.getElementById('txt_name').value;
       var myUrl = 'Popup.aspx?myVal='+MyValue;
         window.showModalDialog(myUrl,'My APPs','status:no; dialogWidth:630px; dialogHeight:420px; help:no; scroll:no; menubar:no; resizable:no');
    }
    
    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div style="text-align: center">
    
    <div style="text-align: center">
    
        <br />
        
    
        <asp:TextBox ID="txt_name" runat="server">
        <br />
        <br />
        <br />
        <input id="Button1" type="button"  önclick="showChildWin()" value="Open Child Window" /></div>
    
        <br />
    
    </div>
    </form>
</body>
</html>


Child Window:
XML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
    <title>Child Window</title>
    <script language="javascript" type="text/javascript">
     
    </script>
    
</head>
<body>
    <form id="form1"  runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <contenttemplate>
    
    
    <div style="text-align: center">
    
        <br />
        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" AllowPaging="true" 
            GridLines="None" Height="67px" 
            style="font-family: Verdana; font-size: 10pt" 
            onselectedindexchanged="GridView1_SelectedIndexChanged" Width="345px">
            <columns>
            <asp:CommandField ShowSelectButton="true"/>
            
            
            </columns>
            <rowstyle backcolor="#F7F6F3" forecolor="#333333" />
            <footerstyle backcolor="#5D7B9D" font-bold="True" forecolor="White" />
            <pagerstyle backcolor="#284775" forecolor="White" horizontalalign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <editrowstyle backcolor="#999999" />
            <alternatingrowstyle backcolor="White" forecolor="#284775" />
        
    
    
        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server">
        <br />
    
    
    
    </div>
    </contenttemplate>
    
    </form>
</body>
</html>


CodeBehind of Child Window:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            string str_val = Request.QueryString[0].ToString();
            TextBox1.Text = str_val;
            SqlDataAdapter da = new SqlDataAdapter("select address from tblEmpDetails", con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();  
        }

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox1.Text=GridView1.SelectedRow.Cells[1].Text;
        }




Help me please.......

I need your help as soon as possible........
Posted
Updated 6-Dec-10 21:57pm
v2
Comments
Dalek Dave 7-Dec-10 3:57am    
Edited for Code Blocks.

Hi,

you can use values session to get the child's value.

try this

good luck

jerem
 
Share this answer
 
Comments
huzaifa.osman 7-Dec-10 3:33am    
Can you explain how to use the session values to get the child's value?
Dalek Dave 7-Dec-10 3:57am    
Good Call.
JeremH 7-Dec-10 4:53am    
You can see on msdn. http://msdn.microsoft.com/en-us/library/ms178581.aspx
Have a look at this article that does almost the same thing: Partial update of parent page via AJAX (ASP.NET 2.0) on close of a child window - conditionally[^]
 
Share this answer
 
I am unable to fix this problem.:confused:

Please help me. I am waiting for your reply.

It's urgent.
 
Share this answer
 
refresh the parent grid.

Refer http://www.codeproject.com/KB/webforms/GridViewRefreshFromParent.aspx

type in google "refresh the parent grid"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900