5

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

abatishchev
  • 95,331
  • 80
  • 293
  • 426
MaxRecursion
  • 4,413
  • 12
  • 40
  • 74

5 Answers5

14

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

Uhehesh
  • 476
  • 2
  • 7
  • 21
HatSoft
  • 10,913
  • 3
  • 27
  • 43
10

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

Daniel A. White
  • 181,601
  • 45
  • 354
  • 430
4

URL-encode the sharp character: %23.

Rob W
  • 328,606
  • 78
  • 779
  • 666
0

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

naveen
  • 51
  • 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
  • 5,315
  • 6
  • 32
  • 49