pass values between forms in windows application..

Posted by Gopal_nivas under C# on 9/10/2009 | Views : 6466 | Status : [Member] | Replies : 6
hi..

how to pass values from one form to another form using c# in windows application...

(for example i want to pass form1 textbox1 value to form2 textbox)
need ur suggestions..

regards
gopal.s




Responses

Posted by: Vinay13mar on: 10/20/2012 [Member] Starter | Points: 25
Posted by: Vuyiswamb on: 9/10/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Morning Gopal_nivas

You can use Session Variables like this

Page 1

Session["Page1Value"] = Textbox1.Text;


and you will access it in page 2 like this


Page 2

TextBox2.Text = Convert.ToString(Session["Page1Value"]);


I need to be sure with Something here. This is a Solution for web Application.

Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudhak on: 9/11/2009 [Member] Starter

Up
0
Down
Hi Gopal

Make the property "modifier" of the control as "public"

initially it will be "private"

declare the object of the windows form and use the . operator to access the control


Regards
Sudha



Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jameschowdare on: 9/12/2009 [Member] Starter

Up
0
Down
first u have to make or create a variable for the first form
ex:form1 obj=new form1();
now
str=obj.textbox1.text;

like this we can use just try if not u get then mail me

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudhak on: 9/12/2009 [Member] Starter

Up
0
Down
hi

If the control's modifier property is private it is not possible to access the control even though you create an instance of the form. After it is set as public only the above code works

Regards
Sudha


Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bubbly on: 10/21/2009 [Member] Bronze

Up
0
Down
Hi,

Either you can create constructor of form with parameters to pass (which will be textbox value) and then from the main form just pass in the value while creating an object of the form.

++
Thanks & Regards,
Deepika

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response