Solved

Display value from Child form to parent TextBox

Posted on 2008-09-29
4
416 Views
Last Modified: 2013-12-17
Hi,
I have winForm (form1 and form2)
On Form1 I have Textbox (txtBox1 and form2  txtbox2 )
On click of button I load form2  ie   form2.showDialog()   ..I have to display value entered in Txtbox2 in form1 textbox (txtbox1)
NOTE : Form1 would be open first.. (How can i reload the form1 back again to show the txtBox2 value)
0
Comment
Question by:dotnet0824
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Jai S
ID: 22595681
say you have a button btnSendValuesToForm1...
here will be the code to displau the textbox2 value in textbox1 of form1

onclick="javascript:parent.document.getElementById('txtbox1').value = document.getElementById('txtbox2').value;window.close();return false;"

if its a server side control then instead of onclick you put onClientClick...which will generate teh onclick event for that button...
0
 

Author Comment

by:dotnet0824
ID: 22595704
Hi, This is windowsForm applicatoin.... Pls I am looking for Code
0
 
LVL 14

Accepted Solution

by:
Jai S earned 500 total points
ID: 22595901
oops sorry...
here it is...

//FORM 1 button click event
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2();
            frm2.ShowDialog();
            textBox1.Text = frm2.textvalue;
        }
 
//Form2 button click event and global variable for 
        public string textvalue;
        public Form2()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            textvalue = textBox1.Text;
            this.DialogResult = DialogResult.OK;
 
        }

Open in new window

0
 
LVL 11

Expert Comment

by:ladarling
ID: 22596923
The click event for your Form2 button should be somthing like:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form1.TextBox1.Text = Me.TextBox2.Text
Me.Close()
End Sub
You can refer to Form1, in this case, by its class name in VB.NET.
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question