一、get方式
发送页:
1.<a href="WebFormA2.aspx?sum=1">进入WebFormA2.aspx</a><br />
2.<asp:TextBox ID="TextBox1" Text="11" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="进入WebFormA2.aspx" OnClick="Button1_Click" />
后台CS代码:
protected void Button1_Click(object sender, EventArgs e)
{
// Server.Transfer("WebFormA2.aspx?name=" + TextBox1.Text);//服务器内部转向,不会调至其他页面。
Response.Redirect("WebFormA2.aspx?name=" + TextBox1.Text);//转向其他页面进行处理,
}
接收页:
接收值:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
后台CS代码:
protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Text = Request["name"];
//this.TextBox1.Text=Request.Params["name"];
//this.TextBox1.Text=Request.QueryString["name"];
}
二、使用内存变量Session和Application
发送页:
<asp:TextBox ID="TextBox1" Text="11" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="进入WebFormB2.aspx"
οnclick="Button1_Click" />
后台CS代码:
protected void Button1_Click(object sender, EventArgs e)
{
Session["name"] = this.TextBox1.Text;
//Application["name"]=this.TextBox1.Text;
Server.Transfer("WebFormB2.aspx");
//Response.Redirect("WebFormB2.aspx");
}
接收页:
接收值:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
后台CS代码:
protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Text = (string)Session["name"];
//this.TextBox1.Text = (string)Application["name"];
}
三、post方式:
发送页:
<form id="form1" runat="server" action="WebFormC2.aspx" method="post">
<input name="txtname" type="text" value="11" />
<input type="submit" value="提交到WebFormC2.aspx" />
</form>
接收页:
接收值: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
后台CS代码:
if (Request.Form["txtname"] != null)
{
TextBox1.Text = Request.Form["txtname"];
TextBox1.Text = Request.Form["SourceData"];
}
在runat=Server中调用POST方法:
<form id="Form1" method="post" runat="server">
<input id="btnTransfer" type="button" οnclick="post();" runat="server" value="提交到WebFormC2.aspx" />
<input type="text" runat="server" id="SourceData" value="11" />
</form>
<form id="forPost" method="post">
<input type="text" runat="server" id="txtname" value="11" />
</form>
<script type="text/javascript">
function post()
{
forPost.action="WebFormC2.aspx";
forPost.submit();
}
</script>