简体   繁体   中英

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

I am passing the 'id' in the url as

<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:

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

 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 . You can place a break point to verify the value of 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.

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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