页面传值方法
1.get 方式
发送页:
1.<a href="WebFormA2.aspx?sum=1">进入WebFormA2.aspx</a><br />
2.<asp:TextBox ID="TextBox1" Text="litianping" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="进入WebFormA2.aspx" OnClick="Button1_Click" />
后台:
protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer("WebFormA2.aspx?name=" + TextBox1.Text);
//Response.Redirect("WebFormA2.aspx?name=" + TextBox1.Text);
}
接受页:
this.TextBox1.Text = Request["name"];
//this.TextBox1.Text=Request.Params["name"];
//this.TextBox1.Text=Request.QueryString["name"];
2.session 和application
发送页:
protected void Button1_Click(object sender, EventArgs e)
{
Session["name"] = this.TextBox1.Text;
//Application["name"]=this.TextBox1.Text;
Server.Transfer("WebFormB2.aspx");
}
接收页:
this.TextBox1.Text = (string)Session["name"];
//this.TextBox1.Text = (string)Application["name"];
3.post方式:
发送页:
<form id="form1" runat="server" action="WebFormC2.aspx" method="post">
<INPUT name="txtname" type="text" value="litianping"/>
<INPUT type="submit" value="提交到WebFormC2.aspx"/>
</form>
接收页:
TextBox1.Text = Request.Form["txtname"];
4.静态变量:
发送页:
//定义一个公共变量
public static string str = "";
protected void Button1_Click(object sender, EventArgs e)
{
str = this.TextBox1.Text;
Server.Transfer("WebFormD2.aspx");
}
接收页:
this.TextBox1.Text = WebFormD1.str;
5.Context.Handler 获取控件:
发送页:
Server.Transfer("WebFormE2.aspx");
接收页:
//获取post过来的页面对象
if (Context.Handler is WebFormE1)
{
//取得页面对象
WebFormE1 poster = (WebFormE1)Context.Handler;
//取得控件
this.TextBox1.Text = ((TextBox)poster.FindControl("TextBox1")).Text;
//this.TextBox1.Text = poster.TextBox1.Text;
}
6.Context.Handler 获取公共属性:
发送页:
//定义一个公共变量
public string strname = "litianping";
protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer("WebFormF2.aspx");
}
接收页:
//获取post过来的页面对象
if (Context.Handler is WebFormF1)
{
//取得页面对象
WebFormF1 poster = (WebFormF1)Context.Handler;
this.TextBox1.Text = poster.strname;
}
Context.Items 变量:
发送页:
protected void Button1_Click(object sender, EventArgs e)
{
Context.Items["name"] = TextBox1.Text;
Server.Transfer("WebFormG2.aspx");
}
接收页:
//获取post过来的页面对象
if (Context.Handler is WebFormG1)
{
this.TextBox1.Text = Context.Items["name"].ToString();
}