0

In cs.aspx page i have a button with following code:

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect("~/cs.aspx?p=ali#25");
}

In page_load i get query string and display it:

protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString["p"] != null)
    {
        string p = Request.QueryString["p"];
        Response.Write("p= "+p);
    }
}

in query string:

p  = ali#25 

but in run time display

p = ali

why string after # not shown.

1
  • # is a reserved character and has meaning in urls; the part of the URL after # is never sent to the server. If you mean to represent the value "ali#25", you will need to url-encode it - but you should be doing that anyway, as a matter of routine. Commented Oct 25, 2013 at 8:43

1 Answer 1

1

found a solution. use Server.UrlEncode:

Response.Redirect("~/cs.aspx?pass="+Server.UrlEncode("a#25"));
Sign up to request clarification or add additional context in comments.

2 Comments

For completeness, the # is being treated as a page anchor. See echoecho.com/htmllinks08.htm
You should always use Url-Encoding before sending the actual values to URL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.