Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get textbox value from one form to another form.
Posted
Comments
Jignesh Khant 24-Aug-13 5:42am    
You can accomplish this using primary key and sessions.
Shambhoo kumar 24-Aug-13 7:25am    
In which type of application you are working, Ex- windows Application or Web Application
BillWoodruff 25-Aug-13 0:46am    
The word "Form" in a question usually means you are using Windows Forms: if you are you are not using Windows Forms, please tag the question.

on first form:
store textbox value in session like this

session["name"]=txtname.Text;

Then on second page retrieve this session:

txtusername.Text=session["name"].Tostring();
 
Share this answer
 
try this..needed the same thing a few days ago and found this solution.....it works..

so just to show an example on how to do it i give you a program that inputs a string from a textbox and writes in a label in second form....so heres what you do..

firstly write in the buttons(used to switch the second form) click event...

 Form2 f = new Form2(textBox1.Text);
            Hide();
            f.ShowDialog();
            Close();
now in the second form s load event do this....

Form1 f=new Form1();
            f.Close();//just for closing the first form......
now we do some thing like this..
public Form2(string name)
        {
            InitializeComponent();
            label1.Text = "Hi there,"+name+".My name is c#";
        }

so the point is you give the name of the textbox as an argument in form1(in the code that loads form2) and in form 2(in the code that describes form 2) you give a string in which the textbox string is added......

hope I was being clear.......tried my best........


Best of luck..

Regards,
       Ahsan Naveed.<pre lang="text">
 
Share this answer
 
Yes,It is possible with Session.But if text box value does not contain sensitive data then you can use Querystring also.
 
Share this answer
 
for that purpose you can use session, views, query string,cookies etc.
 
Share this answer
 
A number of ways are available for this: session, querystring, cookies, etc for Web Form, and Objects in the Windows Form. In windows form, you may be passing the value in the form of a string or you can pass it in the form of object.
 
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