I want to pass '#' to the query string like ?page.aspx?someParam=1234#5
.
Asked
Active
Viewed 1.3k times
5

abatishchev
- 98,240
- 88
- 296
- 433

MaxRecursion
- 4,773
- 12
- 42
- 76
5 Answers
14
Please use Server.UrlEncode
on your querystring that will parse the '#' for you
-
3Actually, I think you want to URLEncode, not HtmlEncode. There's a difference. – David Jul 02 '12 at 16:24
-
3I think you might mean UrlEncode... http://msdn.microsoft.com/en-us/library/zttxte6w.aspx – Chris Jul 02 '12 at 16:24
-
this is a bloody great answer hats-off to hatsoft! – Exitos Aug 03 '12 at 16:12
-
One thing I found out that you dont have to use Server.UrlDecode just use Request.QueryString["someParam"] – Shomaail Oct 30 '16 at 11:37
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