日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Asp.net頁面之間傳遞參數(shù)的幾種方法

 貌似小白 2013-04-19

Asp.net頁面之間傳遞參數(shù)的幾種方法

分類: Asp.Net 157人閱讀 評論(0) 收藏 舉報

Asp.net頁面之間傳遞參數(shù)的幾種方法

第一種方法:
通過URL鏈接地址傳遞Request.QueryString
send.aspx:
   protected void Button1_Click(object sender, EventArgs e)
     {
         Request.Redirect("Default2.aspx?username=honge");
     }
 
receive.aspx:
string username = Request.QueryString["username"];這樣可以得到參數(shù)值。

第二種方法:
通過post方式Request。
send.aspx
<form. id="form1" runat="server" action="receive.aspx" method=post>
     <div>
  <asp:TextBox ID="username" runat="server"></asp:TextBox>
  //<input type="text" name="username" />
        <asp:Button ID="Button1" runat="server" nClick="Button1_Click" Text="Button" />
 </div>
</form>
 
receive.aspx
string username = Ruquest.Form["receive"];//string username = Ruquest["username"];

第三種方法:
通過session
send.aspx:
   protected void Button1_Click(object sender, EventArgs e)
     {
         Session["username"] = "honge";
         Request.Redirect("Default2.aspx");
     }
 
receive.aspx:
string username = Session["username"];這樣可以得到參數(shù)值。

第四種方法:
通過Application
send.aspx:
   protected void Button1_Click(object sender, EventArgs e)
     {
         Application["username"] = "honge";
         Request.Redirect("Default2.aspx");
     }
 
receive.aspx:
string username = Application["username"];這樣可以得到參數(shù)值。

第五種方法:
通過Server.Transfer
send.aspx:
   public string Name
     {
         get {
             return "honge";
         }
     }
     protected void Button1_Click(object sender, EventArgs e)
     {
         Server.Transfer("Default2.aspx");
     }
 
receive.aspx:
    send d = Context.Handler as send ;
         if (d != null)
         {
             Response.Write(d.Name);這樣可以得到參數(shù)值。
         }
  
如果在asp.net 2.0中還可以這樣用:通過PreviousPage
PreviousPage d = Context.Handler as PreviousPage ;
if (d != null)
         {
             Response.Write(d.Name);這樣可以得到參數(shù)值。
         }
也可以這樣用:
send.aspx:
<asp:Button ID="btnSubmit" runat="server" PostBackUrl="~/reveive.aspx" Text="Submit" />

receive.aspx:
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
string name = PreviousPage.Name;這樣可以得到參數(shù)值。
注意:如果你的頁面中用到了MasterPage的話 Server.Transfer 傳遞的 PreviousPage就無效了,不知道這是什么原因.所以在用到MasterPage的話,最好用Session或是 Context.Items["username"]來實現(xiàn).

第六種方法:
通過Cookie
方法類似Session。

第七種方法:
通過Viewstate
Viewstate使用簡單,缺點是只能夠在同一個頁面使用,在ASP.NET2.0里這個問題可以使用Button的PostBackUrl進行解決。

第八種方法:
通過Cache
Cache通常用于緩存服務端某些不常變動的數(shù)據(jù)。
使用Cache存儲數(shù)據(jù)的場合雖然不多,但是畢竟也是一種手段,另外,在使用Cache存儲DataSet時,其實還是引用而不是內容的拷貝。

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多