Counterpart of Javascript decodeURI()

  • Thread starter Thread starter Han
  • Start date Start date
H

Han

Hello

I am passing string from dotnet to javascript. ", ', newline characters, and
something. So I am using httputility.urlEncode() to make it neat.
Now a JS function accepts the encoded string and decode using decodeURI().
But still there are unsolved characters and some +, %, and hex numbers. What
is exact dotnet counterpart of JS decodeURI()?

I am not sure this matters. I am not using typical asp.net + JS. I am using
httputility.urlEncode() withinn XSL extension functions. I think that's not
related with my problem.

Thanks for your reading
 
Han said:
Hello

I am passing string from dotnet to javascript. ", ', newline characters, and
something. So I am using httputility.urlEncode() to make it neat.
Now a JS function accepts the encoded string and decode using decodeURI().
But still there are unsolved characters and some +, %, and hex numbers. What
is exact dotnet counterpart of JS decodeURI()?

As far as I know, there is no counterpart in .NET for the Javascript
function decodeURI.

The counterpart of the HttpUtility.UrlEncode method in Javascript is the
decodeURIComponent function.
 
there are generic problems with using url encode logic for this. url
encode is designed to encode a url, which has some ambiguous characters.
in a url no spaces are allowed, so a "+" is used instead. this means
there is no way in an encoded url to deteremine if a "+" is a plus or a
space. to solve this javascript has encodeURI and decodeURI which
handles this (spaces become %20, plus is left alone).

HttpUtility.UrlEncode converts spaces to "+" and "+" to %2b, so its not
compatible with decodeURI. you will have to write your own encoder.

the other approach is to store the data in a hidden field rather than a
javascript variable, then no decoding is required in javascript, and
HtmlEncode works correctly.

-- bruce (sqlwork.com)
 
Thanks G?an Andersson and bruce barker.

No way to pass arbitrary string dynamically, even to hidden field, I
redesigned the whole process.
 
Han said:
Thanks G?an Andersson and bruce barker.

No way to pass arbitrary string dynamically, even to hidden field, I
redesigned the whole process.

If you put the value in an asp:HiddenField, you don't have to encode it
at all. The control will html-encode the value properly.

When you read the value on the client side, you don't have to decode it
either. The browser has done that.
 
Back
Top