How can I verify Server.HtmlEncode is working?

I have started using Server.HtmlEncode to add some kind of security to my little apps.  They work fine with it, but I want to verify it's actually encoding so I can show the boss.  Is there a way to get the encoded output of a field?

For example, if I have the code below.  I want to see the encoded text just so I know it's encoding properly.
lbl1.Text = Server.HtmlEncode(txt1.Text);

Open in new window

mrcoulsonAsked:
Who is Participating?
 
GiftsonDJohnCommented:
Hi,

It is very simple. Have a multiline textbox, a Label and a Button controls. Copy html code from any webpage. Paste it in the multi line text box. Write the code below on a button click event.

Label1.Text=Server.HtmlEncode(TextBox1.Text);

It should display the actual html code in the Label. If you remove the Server.HtmlEncode methos, the contents will render and display as formatted.
0
 
Anurag ThakurTechnical ManagerCommented:
put in some special symbols in the text box like < > &
encode will convert them to > < &amp; and if encoding is not working then everything will remain the same
0
 
mrcoulsonAuthor Commented:
Let's see.

When I do GiftsonDJohn's suggestion, I get the desired result of a bunch of unparsed code instead of rendered HTML.

When I do ragi's suggestion, the & stays as an &.  

http://www.co.frederick.va.us/apps/email_form/WebForm1.aspx

Jeremy
protected void btn1_Click(object sender, EventArgs e)
        {
            lbl1.Text = Server.HtmlEncode(txt1.Text);
            lbl2.Text = Server.HtmlDecode(lbl1.Text);
        }

Open in new window

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Anurag ThakurTechnical ManagerCommented:
as far as i remember encoding and decoding is not used to display text on the forms
its normally used to when we have to pass the data from the server side to the database or to the remote business object for processing
0
 
mrcoulsonAuthor Commented:
Right.  I just want to verify.  I want a visual way to say, "See?  It works!  Now, I'm the hero."

Jeremy
0
 
Anurag ThakurTechnical ManagerCommented:
you could have shown that in the database too or by saving the encoded string in a text file
anyways good luck - i hope you have got your solution
0
 
mrcoulsonAuthor Commented:
Well, what GiftsonDJohn said makes sense to me, so in the interest of not leaving a question out here too long, he gets it.  

Jeremy
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.