Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Post Data from child popup to parent Form (With out refreshing parent Form)

I have two textbox and one button in parent form with caption OPEN child. I had entered data in one textbox. for other textbox i want to take data from child popup which will open on clicking the button. In child popup, I have one textbox and one button. The data which will be entered in this textbox will come in parent textbox on clicking button. Data is coming from child popup but the parent form is getting refreshed which i dont want. I want data to remain intact in first textbox when data will come in other textbox throgh child popup. Plese give me a suggestion.

Below is the code which i tried. But it is not working for me.

Sample code for Sample1.aspx page at desgin level :

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
    <body>
        <form id="form1" runat="server">
            <table>
                <tr>
                    <td>First Name:</td>
                    <td><asp:TextBox ID="txtName1" Runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Qualification:</td>
                    <td><asp:TextBox ID="txtName2" Runat="server"></asp:TextBox></td>
                </tr>

                <tr>
                    <td align="center" colspan="2">
                    <asp:Button ID="btnSubmit" Runat="server" PostBackUrl="Sample2.aspx" Text="Submit" /></td>
                </tr>
            </table>
        </form>
    </body>
</html>


Sample code for Sample2.aspx page at Desgin level :

ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sample2.aspx.cs" Inherits="Sample2" %>
<%@ PreviousPageType VirtualPath="~/Sample1.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <form id="form1" runat="server">
        <div align="center">
                   <asp:Button ID="btnBack" Runat="server" PostBackUrl="Sample1.aspx" Text="Back" />
            </div>
    </form>
</body>
</html>


Sample code for Sample2.aspx at Code level :

C#
protected void Page_Load(object sender, EventArgs e)
{
    //-- If posted from Sample1.aspx to Sample2.aspx page
    if (PreviousPage != null)
    {
        if (PreviousPage.IsCrossPagePostBack)
        {
            //-- Retrieve the textbox values from Previous page using FindControl method

            TextBox TextBox2;



            TextBox2 = (TextBox)PreviousPage.FindControl("txtName2");

           TextBox2.Text = "MBBS";//This value should be in textbox2 in sample page1 without lossing value of textbox1
        }
        else
        {
            Response.Redirect("Sample1.aspx");
        }
    }
}


Thanks in advance.
Posted
Updated 17-Dec-14 17:57pm
v2

1 solution

You can do that using Javascript
For example i have a Button and when button click i open popup and return the data to main page.

For the Button client click event i have used this in page init method
Here i call the javascript method in onclick client event and also i pass the text box to the java script function to display back the popup result.

C#
imgTool.Attributes.Add("onclick", string.Format("popupOpen({0})", txtbox1.ClientID));


This is javascript code which you can add in your main page and this scriipt will a popop window.kindly change the page name to your popup aspx window.
JavaScript
function popupOpen(textbox_id) {
    if (project_id.disabled || project_id.getAttribute('ReadOnly')) return false;
    var res = ShowPopup("popUpPage.aspx?project_id=" + project_id.value, 820, 551);
    if (!!res) {
        textbox.value = res[0];
       // if (!!car_cd) textbox.value = res[1]; 
    }
}


In you Popup Page you can have close Button and in Close Button Click.pass the result which need to be display in your main page.

C#
protected void btnConfirm_Click(object sender, ImageClickEventArgs e)
    {
        SelectConfirm("Shanu");
    }
 protected void SelectConfirm(yourreturnvalue)
    { 
     Response.Write("<script language='javascript'>");
        Response.Write("window.returnValue = new Array('" +
       yourreturnvalue  + "');window.close();");               
     Response.Write("</script>");
    }
 
Share this answer
 
v4
Comments
Shubhang Acharya 18-Dec-14 3:19am    
Sorry but i can't understand your code how to use it ? Can you please update your ans with some comments.
Shubhang Acharya 18-Dec-14 3:25am    
And if there is gridview in main window and i want to take data of some textboxes of popup window in grid which is on main page(with out loss of main page text box data. ). ?

Any ans will help me..
syed shanu 18-Dec-14 3:27am    
Yes i update it hope it will help you.

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