如何将文本框值从一种形式传递到另一种形式 [英] how to pass the textbox value, from one form to another
问题描述
我创建了两种形式
1)form1
2)form2
我想将文本框的值从form1传递给form2
i have created two forms
1) form1
2) form2
i want to pass the value of the text box from form1 to form2
推荐答案
在form2上创建单个参数构造函数
即
create a single argument constructor on form2
i.e.
class Form2
{
string frm1_tb_value = string.Empty;
Form2(string value)
{
frm1_tb_value = value;
}
}
现在,当您在Form1上创建Form2的对象以打开它时.在Form2构造函数的括号内传递文本框值
即
now when you create an object of Form2 on Form1 for opening it. pass textbox value inside the bracess of Form2 constuctor
i.e
Form2 frm = new Form2(textbox1.Text);
frm.Show();
这是将价值传递给其他形式的方法之一. :)
this is one of the ways, you can pass value to other forms. :)
有多个选项,
1)QueryString-该值将与url
一起传递
在form1中设置值
there are multiple options,
1) QueryString - the value will be passed with the url
in form1 set the value
Response.Redirect("~/form2.aspx?id=" + textbox1.text + "&city=" + textbox2.text);
在form2
in form2
string strValue1 = Request.QueryString["id"];
string strValue2 = Request.QueryString["city"];
2)会话状态
在form1中设置值
2) Session State
in form1 set the value
Session["id"] = textbox1.text;
在form2中获取值
in form2 get the value
string strValue = convert.toString(Session["Id"]);
其余选项最不重要,但是,我要在此处说明,针对这些主题使用Google来阅读一些基本细节.
3)跨页发布
4)饼干
5)应用状态
标记为答案是否有帮助
the rest of the options are least important, however, I am stating here, do Google for these topics, to read some basic details.
3) cross page posting
4) cookies
5) application state
mark as answer if helps you
声明会话变量,例如,
形式1:
declare session variable like that,
form1:
session["value"]=textbox1.text;
形式2:
form2:
<pre lang="c#">
textbox1.text = session ["value"];
textbox1.text=session["value"];
这篇关于如何将文本框值从一种形式传递到另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!