ASP.net参数传递总结

同一页面.aspx与.aspx.cs之间参数传递
1. .aspx.cs接收.aspx的参数:由于.aspx和.aspx.cs为继承关系,所以.aspx.cs可以直接对.aspx中的ID进行值提取,具体语句为string b = a.text; 其中a为.aspx中的文本框的ID;
2. .aspx接收.aspx.cs的变量:将.aspx.cs的变量设为全局变量,在.aspx中直接引用<%=a %>,这里a为.aspx.cs
中声明的全局变量;
 
 
 不同页面之间的参数传递
1.URL传递参数方法,有两种方法:
  第一种:send.aspx
             <a href=receive.aspx?a=b></a>
                  receive.aspx.cs
            string c = Request.QueryString["a"];
  第二种:send.aspx.cs:
  protected void Button1_Click(object sender, EventArgs e)
    {
        Request.Redirect("receive.aspx?a=b");
    }
                 receive.aspx.cs:
  string username = Request.QueryString["username"];
2. Form表单POST方法
send.aspx
<form id="form1" runat="server" action="receive.aspx" method=post>
    <div>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        <asp:TextBox ID="a" runat="server"></asp:TextBox>
   </div>
    </form>
receive.aspx.cs
string b = Ruquest.Form["a"];
3.通过session方法传递参数
send.aspx.cs:
  protected void Button1_Click(object sender, EventArgs e)
    {
        Session["username"] = "a";
        Request.Redirect("receive.aspx");
    }
 receive.aspx:
 string username = Session["username"];
原文地址:https://www.cnblogs.com/Ghazi/p/6000432.html