Live Chat Icon For mobile
Live Chat Icon

How to select a value from a child form and send it to parent form

Platform: ASP.NET| Category: Miscellaneous

page1.aspx


<asp:TextBox id='txtSelect' style='Z-INDEX: 101; LEFT: 186px; POSITION: absolute; TOP: 19px'
	runat='server'></asp:TextBox>
<a href='javascript:my_window = window.open(’page2.aspx?formname=Form1.txtSelect’ , ’my_window’,’width=300,height=300’); my_window.focus()'>
	Select CategoryName</a>

page2.aspx


<asp:DropDownList id='DropDownList1' style='Z-INDEX: 101; LEFT: 180px; POSITION: absolute; TOP: 66px'
	runat='server' AutoPostBack='True'>
<asp:Label id='Label1' style='Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 66px' runat='server'>Select Category  Name
<asp:Literal id='Literal1' runat='server'>

VB.NET


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	’Put user code to initialize the page here
	If Not Page.IsPostBack Then
		’Fill DataSet ....	
	            DropDownList1.DataSource = ds.Tables(0)
	            DropDownList1.DataTextField = 'CategoryName'
	            DropDownList1.DataValueField = 'CategoryId'
	            DropDownList1.DataBind()
	End If
End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
	Try
	            Dim strjscript As String = '<script language=''javascript''>'
	            strjscript = strjscript & 'window.opener.' & HttpContext.Current.Request.QueryString('formname') & '.value = ’' & DropDownList1.SelectedItem.Text & '’;window.close();'
	            strjscript = strjscript & '</script>'
	            Literal1.Text = strjscript
	Catch ex As Exception
	            Response.Write(ex.Message)
	End Try
End Sub

C#


private void Page_Load(object sender, System.EventArgs e)
{
	// Put user code to initialize the page here
	if (!Page.IsPostBack )
	{
	            //Fill DataSet
                            DropDownList1.DataSource = ds.Tables[0];
	            DropDownList1.DataTextField = 'CategoryName';
	            DropDownList1.DataValueField = 'CategoryId';
	            DropDownList1.DataBind();
	}
}

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
	try
	{
	            string strjscript  = @'<script language=''javascript''>';
	            strjscript = strjscript + 'window.opener.' + HttpContext.Current.Request.QueryString['formname'].ToString () + '.value = ’' + DropDownList1.SelectedItem.Text + '’;window.close();';
	            strjscript = strjscript + '</script>';
	            Literal1.Text = strjscript;
	}
	catch(Exception ex)
	{
	           Response.Write (ex.Message );
	}
}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.