我们经常可以看到类似这样的URL:http://localhost/news/WebForm4.aspx?name=upup&password=12345
这样的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中的情况如下:
在WebForm4.aspx中的地址栏中的URL就是:http://localhost/news/WebForm4.aspx?name=upup&password=12345
实现访问URL中的数据的代码为:
Me.txtna.Text = Request("name")
Me.txtpwd.Text = Request("password")