ASP.NET參數傳遞總結

來源:互聯網
上載者:User

標籤: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參數傳遞總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.