5

I want to pass '#' to the query string like ?page.aspx?someParam=1234#5.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
MaxRecursion
  • 4,773
  • 12
  • 42
  • 76

5 Answers5

14

Please use Server.UrlEncode on your querystring that will parse the '#' for you

Uhehesh
  • 506
  • 2
  • 8
  • 22
HatSoft
  • 11,077
  • 3
  • 28
  • 43
10

Try using %23. This is the url encoded value for #.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
4

URL-encode the sharp character: %23.

Rob W
  • 341,306
  • 83
  • 791
  • 678
0

try using escape(url parameter value) method in url instead of only parameter value

naveen
  • 61
  • 1
  • 1
0

The best way to pass #, & and other special characters without causing problems in asp.net query string is to use Server.UrlEncode()
See the following example.

  private void btnSubmit_Click(object sender, System.EventArgs e)
  {
     Response.Redirect("page.Aspx?"+"someParam="+Server.UrlEncode("1234#5")); 
  } 


or use %23 replacing # but I think the more suitable way is using Server.UrlEncode() so you can use other special characters without any problem.

Nishantha
  • 6,065
  • 6
  • 33
  • 51