简体   繁体   English

在ASP.NET网页之间传递值

[英]Pass value between asp.net web page

I'm using asp.net with c# in backcode. 我在反向代码中使用带有c#的asp.net。 On my first page, I have a hyperlink with NavigateUrl ="Order.aspx?productId = " + ProductID . 在我的第一页上,我有一个超链接,其中包含NavigateUrl ="Order.aspx?productId = " + ProductID I want to transfer ProductID in Order.aspx file. 我想在Order.aspx文件中传输ProductID So, how to get it in target file : Order.aspx . 因此,如何在目标文件Order.aspx获取它。

I used a lable to display in Order.aspx file 我用一个标签显示在Order.aspx文件中

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

lblTest.Test = productId

But lblTest didn't display anything 但是lblTest没有显示任何内容

Thanks. 谢谢。

You would read the QueryString values of the Request object. 您将读取Request对象的QueryString值。

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

You'd have to parse it into an integer if that is what it is. 如果是这样,则必须将其解析为整数。

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

You might also want to get rid of the spaces in your URL. 您可能还希望摆脱URL中的空格。

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

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

Use the request collection 使用请求集合

string productId = Request["productId"];

Be careful what you do with this variable. 小心使用此变量。 Eg don't store it directly in a database or append it to an inline query. 例如,不要将其直接存储在数据库中或将其附加到内联查询中。

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

Your code: 您的代码:

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

Remove the space My code: 删除空格我的代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM