簡體   English   中英

如何在兩個HTML頁面之間傳輸數據

[英]How data transfer between two html page

我試圖在一個頁面中顯示超鏈接,並且當用戶單擊鏈接時,頁面處於導航狀態,但是我想獲取超鏈接的名稱並在其他網頁中顯示為標簽。 在這里,我正在嘗試使用cookie,但是cookie僅采用數據庫的最后一個值,可以將所有值存儲在cookie中? 謝謝

 String sql1 = "select title,song_id from up_song where Song_type='Indian Pop Album'";
    adpt = new SqlDataAdapter(sql1, cn);
    ds = new DataSet();
    adpt.Fill(ds, "title1");
    var last6Uploaded1 = ds.Tables["title1"]
                              .AsEnumerable()
                              .OrderByDescending(r=> r.Field<int>("song_id"))
                              .Take(2);
    foreach (DataRow row in last6Uploaded1)
    {

        int songID = row.Field<int>("song_id");
        // you don't need the array of hyperlinks neither
        HyperLink hl = new HyperLink(); 
        hl.ID = "hyperlink" + songID;
        string title = row.Field<string>("title");
        hl.Text = title;
        hl.NavigateUrl = "Downloadpage.aspx";
        hl.ForeColor = System.Drawing.Color.White;
        HttpCookie coo = new HttpCookie("song");
        coo["sogtit"] = title;
        Response.Cookies.Add(coo);
        Panel2.Controls.Add(hl);
        Panel2.Controls.Add(new LiteralControl("<br>"));
     }

Cookies可以存儲多個值,這是您可以執行的操作:

string title = row.Field<string>("title");
string song_id = row.Field<int>("song_id").ToString();

HttpCookie coo = new HttpCookie("song");
cookie.Values.Add("songtit", title);
cookie.Values.Add("song_id", song_id);

您將像這樣在目標頁面中檢索值:

string title = response.Cookies["song"]["songtit"];
string song_id = response.Cookies["song"]["song_id"];

在網頁之間傳遞數據的另一種常見方式是通過從目標頁面中的QueryString獲取的請求參數。 像這樣設置您的URL:

hl.NavigateUrl = "Downloadpage.aspx?name=" + title;

在它的Page_Load事件處理程序集中的Downloadpage.aspx中:

yourLabel.Text = Request.QueryString["name"];

其中, yourLabel是要為其設置文本的標簽的名稱。

您可以像這樣通過請求傳遞多個參數:

hl.NavigateUrl = "Downloadpage.aspx?name=" + title + "&otherParam=" + otherParam;

在目標頁面中,您可以通過Request.QueryString["otherParam"]獲取第二個參數的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM