繁体   English   中英

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

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

我在网址中传递“ id”为

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

“ id”在目标页面的网址中可见,但是当我尝试获取id时,如下所示:

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

这是行不通的。

问题出在哪儿?

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

替换为“”到“”。 试试这个代码

如果要获取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"];
        }

因为每当url重定向到single product.aspx ,它首先在Single Product.cspage load中执行代码。 您可以放置​​一个断点以验证id的值。

提及代码应该有效,

如果您使用的是Gridview,则可以使用模板字段来运行代码,这正如我所尝试的那样有效。

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

请在实际使用这些值的位置和方式上共享您的.aspx页代码。

暂无
暂无

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

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