I wan to tranfer the value barcode from abc.aspx to cde.aspx and display in other page

this is the code from abc.aspx

 <asp:HyperLink ID="hlBarcode" runat="server"   NavigateUrl='<%# "~/SearchStock.aspx?BC=" + Eval("Barcode")%>'  >

this is the code from cde.aspx.cs

 protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Barcode"] != null)
                txtBarcode.Text = Request.QueryString["Barcode"];
        }

but my txtBarcode.Text cannot get anything...how to solved it?

Dani AI

Generated

Good catch from and — the most likely cause is a mismatch between the query-string key you create and the key you read on the other page. Make the parameter name consistent (either send it as "BC" and read "BC", or send "Barcode" and read "Barcode").

Other checks and tips that often get missed:

  • Inspect the rendered anchor in the browser (View Source or Inspect Element). If the href has no query string, the data-binding expression in the markup never ran. If the hyperlink is inside a template control, make sure the parent is actually data-bound (or call DataBind at the right time).
  • If the link is built with a data-binding expression, remember those evaluate only during data binding. If the hyperlink lives outside a data-bound context, use server-side code or a different markup approach.
  • If the barcode can contain spaces or punctuation, URL-encode it before putting it into the query string (for example with HttpUtility.UrlEncode or Server.UrlEncode) so the value isn’t truncated or mangled.
  • Confirm the target textbox is a server control with the correct ID and runat="server" so server code can set its Text, and ensure you’re not accidentally overwriting that value later in the page lifecycle.

Alternatives and safety:

  • If you don’t want visible query strings, use Session, Server.Transfer with Context.Items/PreviousPage, or a cross-page postback — each has tradeoffs for scalability and user experience.
  • Always validate/sanitize the incoming barcode on the server before using it (don’t trust query-string data).

Quick debug: copy the generated href from the browser and paste it into the address bar to see what the receiving page actually gets.

Recommended Answers

All 2 Replies

You are referencing the wrong query string parameter. In your abc.aspx file, the query string parameter you used is BC, not Barcode. So just change line 3 to "BC".

hii..

your query string name is wrong. replace 'BC' instead of 'Barcode'

 protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["BC"] != null)
                txtBarcode.Text = Request.QueryString["BC"];
        }

thn it'll work fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.