Question

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?

Was it helpful?

Solution

Use

encodeURIComponent()

before passing that.

Like:

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

or just encode the entire url.

OTHER TIPS

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).

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

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top