如何将文本框值从一个表单获取到另一个表单 [英] How to get textbox value from one form to another form

查看:80
本文介绍了如何将文本框值从一个表单获取到另一个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个表单到另一个表单获取文本框值

解决方案

在第一个表单上:

在这样的会话中存储文本框值



session [name] = txtname.Text;



然后在第二页上检索此会话:



txtusername.Text = session [name]。Tostring();


< blockquote>

尝试这个..前几天需要同样的东西,发现这个解决方案.....它有效.. 

所以只是为了展示一个如何的例子做到这一点,我给你一个程序,从文本框输入一个字符串,并以第二种形式写入标签....所以你继续做什么..

首先写入按钮(用于切换)第二种形式)click事件...

Form2 f = new Form2(textBox1.Text);
隐藏();
f.ShowDialog();
关闭();
现在在第二种形式的s load事件中执行此操作....

Form1 f = new Form1();
f.Close(); //只是为了关闭第一个表单......
现在我们做这样的事情..
public Form2(string name)
{
InitializeComponent();
label1.Text =你好,+名字+。我的名字是c#;
}

所以重点是你在form1(在加载form2的代码中)和表单2(在描述表单2的代码中)中给出文本框的名称作为参数你给一个字符串,其中添加了文本框字符串......

希望我很清楚......我尽力了........


好​​运..

问候,
Ahsan Naveed。< pre lang =text>


是的,可以使用Session.But,如果文本框值不包含敏感数据,那么您也可以使用Querystring。


I want to get textbox value from one form to another form.

解决方案

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();


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">


Yes,It is possible with Session.But if text box value does not contain sensitive data then you can use Querystring also.


这篇关于如何将文本框值从一个表单获取到另一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆