Please help me to get query string value from the URL.
http://test.com/test.aspx#id=test
I tried to access with
Request.QueryString["id"]
Its getting null value.Please suggest how to access id from the url.
Thanks
Please help me to get query string value from the URL.
http://test.com/test.aspx#id=test
I tried to access with
Request.QueryString["id"]
Its getting null value.Please suggest how to access id from the url.
Thanks
I agree with everyone that the #
should be a ?
, but just FYI:
Note it isn't actually possible get the anchor off the URL, for example:
http://test.com/test.aspx#id=test
The problem is that # specified an anchor in the page, so the browser sees:
http://test.com/test.aspx
And then looks in the page for
<a id="test">Your anchor</a>
As this is client side you need to escape the # from the URL - you can't get it on the server because the browser's already stripped it off.
If you want the part after the # you have to copy it using Javascript before the request is sent to the server, and put the value in the querystring.
More info here c# get complete URL with "#"
A query string starts with a question mark ?
not a hash #
.
Try:
http://test.com/test.aspx?id=test
Using a hash, you're asking to jump to a named anchor within the document, not providing a query string
Your URL is not valid.
http://test.com/test.aspx#id=test
refers to a bookmark named id=test
.
You should use
http://test.com/test.aspx?id=test
And then Request.QueryString["id"]
will work.
If you would like to use it as hash tag you can use:
string value = Request.Url.ToString().Split('#')[1];
with this code, you will have your hash tag value.