5种ASP.NET页面间传递参数实例代码
生活随笔
收集整理的這篇文章主要介紹了
5种ASP.NET页面间传递参数实例代码
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
本文假設(shè)第一個(gè)頁(yè)面為send.aspx,第二個(gè)頁(yè)面為receive.aspx
1、通過URL鏈接地址傳遞
(1)?send.asp代碼
(2)?receive.aspx代碼
2、POST方式傳遞
(1)?send.asp代碼
(2)?receive.aspx代碼
3、Session方式傳遞
(1)?send.asp代碼
(2)?receive.aspx代碼
4、Application方式傳遞
(1)?send.asp代碼
(2)?receive.aspx代碼
5、使用Server.Transfer進(jìn)行傳遞
(1)?send.asp代碼
(2)?receive.aspx代碼
1、通過URL鏈接地址傳遞
(1)?send.asp代碼
| protected?void?Button1_Click(object?sender,?EventArgs?e)???? ????{???? ????????Request.Redirect("Default2.aspx?username=honge");???? ????}??? |
(2)?receive.aspx代碼
| string?username?=?Request.QueryString["username"];//這樣可以得到參數(shù)值。 |
2、POST方式傳遞
(1)?send.asp代碼
| <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="username"?runat="server"></asp:TextBox>???? </div>???? </form>?? |
(2)?receive.aspx代碼
| string?username?=?Ruquest.Form["receive"];? |
3、Session方式傳遞
(1)?send.asp代碼
| protected?void?Button1_Click(object?sender,?EventArgs?e)???? ????{???? ????????Session["username"]?=?"honge";???? ????????Request.Redirect("Default2.aspx");???? ????}??? |
(2)?receive.aspx代碼
| string?username?=?Session["username"];//這樣可以得到參數(shù)值。? |
4、Application方式傳遞
(1)?send.asp代碼
| protected?void?Button1_Click(object?sender,?EventArgs?e)???? ????{???? ????????Application["username"]?=?"honge";???? ????????Request.Redirect("Default2.aspx");???? ????}?? |
(2)?receive.aspx代碼
| string?username?=?Application["username"];這樣可以得到參數(shù)值。 |
5、使用Server.Transfer進(jìn)行傳遞
(1)?send.asp代碼
| public?string?Name???? ????{???? ????????get?{???? ????????????return?"honge";???? ????????}???? ????}???? ????protected?void?Button1_Click(object?sender,?EventArgs?e)???? ????{???? ????????Server.Transfer("Default2.aspx");???? ????}??? |
(2)?receive.aspx代碼
| send?d?=?Context.Handler?as?send?;???? ????????if?(d?!=?null)???? ????????{???? ????????????Response.Write(d.Name);//這樣可以得到參數(shù)值。???? ????????}?? |
轉(zhuǎn)載于:https://www.cnblogs.com/princessEE/archive/2009/09/21/1570879.html
總結(jié)
以上是生活随笔為你收集整理的5种ASP.NET页面间传递参数实例代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Intel与SK海力士“联姻”首作:So
- 下一篇: 神似华为Mate 40!鼎桥TD Tec