假如第一个页面文件This.aspx如下所示:
<html>
<body>
请单击下面的超链接<p>
<a href="Other.aspx?user_name=令狐冲&age=22">显示</a>
</body>
</html>
另一个页面文件Other.aspx读取参数:<body>
请单击下面的超链接<p>
<a href="Other.aspx?user_name=令狐冲&age=22">显示</a>
</body>
</html>
<script language="VB" runat="server">
Sub page_load(Sender As Object, E As EventArgs)
Dim user_name As String '定义一个用户名变量
Dim age As Integer '定义一个年龄变量
user_name=Request.QueryString("user_name") '获取用户名
age=Request.QueryString("age") '获取年龄
Message.Text=user_name & "您好"
Message.Text=Message.Text & ",您的年龄是" & age.ToString
End Sub
</script>
<html>
<body>
<h4 align="center">Request对象示例</h4>
<form runat=server>
<asp:label id="Message" runat=server/>
</form>
</body>
</html>
读出的中文参数name出现乱码,而且后面的age参数也不能读取。解决的方法是修改This.aspx文件如下:Sub page_load(Sender As Object, E As EventArgs)
Dim user_name As String '定义一个用户名变量
Dim age As Integer '定义一个年龄变量
user_name=Request.QueryString("user_name") '获取用户名
age=Request.QueryString("age") '获取年龄
Message.Text=user_name & "您好"
Message.Text=Message.Text & ",您的年龄是" & age.ToString
End Sub
</script>
<html>
<body>
<h4 align="center">Request对象示例</h4>
<form runat=server>
<asp:label id="Message" runat=server/>
</form>
</body>
</html>
<html>
<body>
请单击下面的超链接<p>
<a href="Other.aspx?user_name=<%=Server.UrlEnCode("令狐冲")%>&age=22">显示</a>
</body>
</html>
<body>
请单击下面的超链接<p>
<a href="Other.aspx?user_name=<%=Server.UrlEnCode("令狐冲")%>&age=22">显示</a>
</body>
</html>