在asp.net网页之间传递值

时间:2011-11-29 21:50:00

标签: c# asp.net

我在backcode中使用带有c#的asp.net。在我的第一页上,我有一个超链接 NavigateUrl ="Order.aspx?productId = " + ProductID。我想在ProductID文件中转移Order.aspx。 那么,如何在目标文件中获取它:Order.aspx

我使用了一个标签来显示Order.aspx文件

string productId = Request.QueryString["productId"];

lblTest.Test = productId

lblTest没有显示任何内容

感谢。

5 个答案:

答案 0 :(得分:4)

您将读取Request对象的QueryString值。

string productId = Request.QueryString["productId"];

如果它是这样的话,你必须将它解析成一个整数。

NavigateUrl ="Order.aspx?productId = " + ProductID

您可能还想删除网址中的空格。

答案 1 :(得分:1)

String value = Request.QueryString["productId"];

建议您验证Request.QueryString [“productId”]是否确实存在。

答案 2 :(得分:0)

使用请求集合

string productId = Request["productId"];

小心你对这个变量的处理方式。例如。不要将其直接存储在数据库中或将其附加到内联查询中。

答案 3 :(得分:0)

如果ProductID是服务器端变量,请使用: NavigateUrl =“Order.apx?productId =”<%= ProductID%>

答案 4 :(得分:0)

您的代码:

="Order.aspx?productId = " + ProductID;

删除空格 我的代码:

="Order.aspx?productId=" + ProductID;