標籤:os io strong for ar div cti sp on
同一頁面.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"];
ASP.NET參數傳遞總結