Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Counterpart of Javascript decodeURI()

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Han - 25 Jul 2007 16:19 GMT
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
Göran Andersson - 25 Jul 2007 17:42 GMT
> Hello
>
[quoted text clipped - 3 lines]
> 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.

Signature

Göran Andersson
_____
http://www.guffa.com

bruce barker - 25 Jul 2007 17:43 GMT
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)

> Hello
>
[quoted text clipped - 9 lines]
>
> Thanks for your reading
Han - 26 Jul 2007 05:23 GMT
Thanks G?an Andersson and bruce barker.

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

> Hello
>
[quoted text clipped - 9 lines]
>
> Thanks for your reading
Göran Andersson - 26 Jul 2007 16:25 GMT
> 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.

Signature

Göran Andersson
_____
http://www.guffa.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.