Mark Highfield
Mark Highfield

Reputation: 453

unable to pass # character via querystring

I have a link being created in jquery that has a querystring value of "www.mypage.com?id=" + id

the problem I'm having is that in a recent case, some of the id's have the # character in them, which is breaking the id value. How can I create a querystring with a # in it, from jquery, and read that value accurately in C# when the page loads?

Upvotes: 2

Views: 905

Answers (4)

Orlando Herrera
Orlando Herrera

Reputation: 3531

I hope this can help you, it is a small peace of code:

<body onload="catchingData()">


<script type="text/javascript" language="javascript">
    function catchingData() {
        var myurl = document.URL;
        var myToken = myurl.split("access_token"); //---> Split your url in the browser
        self.location = "yourWebForm.aspx" + "?" + myToken[1];
    }
</script>

Upvotes: 0

Bill
Bill

Reputation: 1479

You could find/replace instances of '#' and swap for '%23' which is the escape character.

For reference, I found this list of common escape characters in a quick Google search: http://www.werockyourweb.com/url-escape-characters

Upvotes: 0

Moo-Juice
Moo-Juice

Reputation: 38800

Don't pass the '# as part of the id. It is used to delimit parts of the url. Either escape it or fix the code that is sending the # as part of the id (because I suspect it shouldn't).

Upvotes: 1

Amit Joki
Amit Joki

Reputation: 59252

Use

encodeURIComponent()

before passing that.

Like:

"www.mypage.com?id=" + encodeURIComponent(id);

or just encode the entire url.

Upvotes: 8

Related Questions