如何显示Request.QueryString数据

时间:2010-06-17 19:21:45

标签: asp.net

我试过的代码没有显示任何内容。

测试1.aspx

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect("Test2.aspx?ID=1");
}

Test2.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="WebApplication5.test2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text='<%=Request.QueryString["ID"] %>'></asp:Label>

    </div>
    </form>
</body>
</html>

1 个答案:

答案 0 :(得分:4)

在第二页的代码隐藏文件Page_Load事件中,放置以下代码:

lblId.Text = Request.QueryString["ID"].ToString();

其中lblId是第二页上Label控件的ID。

Grz,Kris。