Should it be Encode or Decode?

A

AAaron123

....snip...

<itemtemplate>


<p><%# Server.HtmlEncode(Eval("Caption").ToString()) %>

....snip...

This is not my code.

I'm not sure when to Encode and when to Decode but I think in markup one
wold Decode.

I think Decode changes %20 to a space. Right?

Somethings funny because I tried both Encode and Decode but I still see %20
in the text in the browser.

Should it be Encode or Decode?



Thanks
 
A

AAaron123

Mark Rae said:
In which case, you already know the answer...
But I don't. I've read the doc on Encode and Decode but don't know which is
for converting %20 to a space.

I tried both and %20 shows for both.

It would help to debug if I knew which was the correct one to use.

Thanks
 
A

AAaron123

You put your figure on a problem.
I looked at the DB and all captions have embedded spaces except the one I
happen to pick to test with.
So it looks like (maybe) the author wanted spaces in the DB, but why would
she then use Encode to display it?
Is it true that Encode converts %20 to a space or does Decode do that?
So maybe she wanted to convert space to %20 before storing. Which should be
used for that, Encode or Decode



Thanks
 
A

AAaron123

Thanks
That helped a lot.
Since you say
"Storing url encoded values in a db will be a nightmare"
and since all the other entries have not been encoded, I looked at all the
Binds and none do any encoding.
So I think that one entry must have gotten in there sometimes during debug.
I have no idea how!

I'll simply delete it and which to see if the problem re-occurs.

Thanks again
 
A

AAaron123

I did in a .aspx file:

Test string AA AABB%20BBCC+CCDD?DD
HtmlEncodeAA AABB%20BBCC+CCDD?DD
HtmlDecodeAA AABB%20BBCC+CCDD?DD
UrlEncodeAA+AABB%2520BBCC%2bCCDD%3fDD
UrlDecodeAA AABB BBCC CCDD?DD
UrlDecodeOfEncodeAA AABB%20BBCC+CCDD?DD
UrlPathEncodeAA%20AABB%20BBCC+CCDD?DD

And got:

Test string AA AABB%20BBCC+CCDD?DD
HtmlEncodeAA AABB%20BBCC+CCDD?DD
HtmlDecodeAA AABB%20BBCC+CCDD?DD
UrlEncodeAA+AABB%2520BBCC%2bCCDD%3fDD
UrlDecodeAA AABB BBCC CCDD?DD
UrlDecodeOfEncodeAA AABB%20BBCC+CCDD?DD
UrlPathEncodeAA%20AABB%20BBCC+CCDD?DD

So I do have a better understanding of encode/decode now.
I now believe the string that I couldn't understand shouldn't have been
there in the first place.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top