简体   繁体   English

Request.Querystring [“ id”]在aspx.cs页面中不起作用

[英]Request.Querystring[“id”] is not working in aspx.cs page

I am passing the 'id' in the url as 我在网址中传递“ id”为

<a href="Single Product.aspx?id=<%#Eval("Category_type_ID")%>"><%#  Eval("Category_type_Name") %></a>

'id' is visible in the url of target page but when I try to fetch the id like follows: “ id”在目标页面的网址中可见,但是当我尝试获取id时,如下所示:

string val = Request.QueryString["id"];

it does not work. 这是行不通的。

Where is the problem? 问题出在哪儿?

<a href='Single Product.aspx?id=<%#Eval("Category_type_ID")%>'><%#  Eval("Category_type_Name") %></a>

Replace with "" to ''. 替换为“”到“”。 try this code 试试这个代码

if you are getting the url localhost:6040/Website/Single%20Product.aspx?id=3 the code must be implemented in Single Product.cs like 如果要获取url localhost:6040/Website/Single%20Product.aspx?id=3该代码必须在Single Product.cs实现,例如

 protected void Page_Load(object sender, EventArgs e)
        {
          string test = Request.QueryString["id"];
        }

because whenever the url redirects to single product.aspx first of all it executes the code in the page load of Single Product.cs . 因为每当url重定向到single product.aspx ,它首先在Single Product.cspage load中执行代码。 You can place a break point to verify the value of id . 您可以放置​​一个断点以验证id的值。

The mention code should work, 提及代码应该有效,

if you are using a Gridview, you can use a template field to get the code run, this is working as I have tried. 如果您使用的是Gridview,则可以使用模板字段来运行代码,这正如我所尝试的那样有效。

<asp:TemplateField HeaderText="Link" ItemStyle-Width="150">
                <ItemTemplate>
                    <a href="Default2.aspx?id=<%# Eval("CountryId") %>" ><%# Eval("CountyName") %></a>                           
                </ItemTemplate>
            </asp:TemplateField>

please share your .aspx page code where and how you actually consume the values. 请在实际使用这些值的位置和方式上共享您的.aspx页代码。

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

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