Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 6th, 2004, 11:35 PM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi bekim,

following code works well

string str = "This is a <Test String>.";
TextBox1.Text = str.ToString();
string encodedstr = System.Web.HttpUtility.UrlEncode(str.ToString());
TextBox2.Text = encodedstr.ToString();
string decodedstr = System.Web.HttpUtility.UrlDecode(encodedstr);
TextBox3.Text = decodedstr.ToString();

:)

 
Old October 6th, 2004, 11:56 PM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi bekim,

for HtmlEncode, try this

string str = "This is a <Test String>.";
string htmle = System.Web.HttpUtility.HtmlEncode(str.ToString());
TextBox4.Text = htmle.ToString();
string htmld = System.Web.HttpUtility.HtmlDecode(htmle.ToString() );
TextBox5.Text = htmld.ToString();

Difference is when you use urlencode it converts spaces into '+'

when you execute UrlEncode and HtmlEncode for the same string, you can find the difference.

:)


 
Old October 7th, 2004, 05:17 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Butterfly,
I think something else is the matter.
When I run:

string str = "This is a <Test String>.";
Response.Write(str);

I get "This is a ." not "This is a <Test String>."

For some reason the "<Test String>" doesn't show.
I even use validaterequest=false at @Page in html part.

What could be the problem??


 
Old October 7th, 2004, 08:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

THe string is decoded, so it thinks <Test String> is an HTML element. If you view source, you will see it. If you want it rendered appropriately, do:

Response.Write(Server.HtmlEncode(str))

When you render the text as a link, it then should appear appropriately encoded. Did you try adding it as a querystring value and seeing it there? It should something like:

This+is+a+%3cTest+String%3e

But instead of +, you should get %20. However, in your app, if you write to a string, it will appear as you see it.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy hyperlink ques with iframe bekim Javascript How-To 4 September 21st, 2005 02:45 AM
Easy Ques -- Datetime validation for Access bekim Access 2 June 16th, 2005 01:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.