How to pass ‘#’ in query string

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 2

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

Method 3

URL-encode the sharp character: %23.

Method 4

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

Method 5

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x