通過URL實現在不同頁面間傳輸資料
阿新 • • 發佈:2019-01-23
這樣的URL可以實現網頁間的資料傳遞,就是切換到新的網頁時,舊網頁資料傳給了新網頁。以上面的URL說明:
URL中問號後面跟隨的就是所要傳遞的引數及資料。
輸入資料:
按鈕的事件如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim url As String = "WebForm4.aspx?name=" & Server.UrlEncode(txtna.Text) & "&password=" & Server.UrlEncode(txtpwd.Text)
Response.Redirect(url)
End Sub
注意 Server.UrlEncode(txtna.Text) 最好進行編碼,否則輸入upup&upup這樣的資料時,只會得到前面的upup
在webform4.aspx中的情況如下:
實現訪問URL中的資料的程式碼為:
Me.txtna.Text = Request("name")
Me.txtpwd.Text = Request("password")