How to add HTML Encoding to Editor Ajax Control

Is it possible to add another viewing option button to the "Editor" Ajax control to view the page with the HTML "Encoded" so that "<", ">" and " " " show as "&lt;", "&gt;" and "&Quote;"?

The Editor control currently has "Design Mode", "HTML text" and "Preview".  I'd like to add the capability to view "Encoded HTML".

I found the standalone example of an Encoder, but it only encodes part of the html code I put in the textbox.  Say I put 15 lines of html in the textbox, it only encodes 8 or 9 of the lines and leaves a bunch of "<" and ">" characters in the text after "encoding".  I'd settle for fixing this, but it would be really nice to have the function to create some html and encode it all in one editor.
.aspx:

<asp:Label ID="lblText" runat="server" Text="Enter your HTML Code here:" />
<asp:TextBox ID="txtReadScript" runat="server" Width="165px" />
<asp:Button ID="cmdEncode" runat="server" Text="Encode" />
<br /><br /><br />
<asp:TextBox ID="txtMsg" runat="server" Width="284px" TextMode="MultiLine" Height="146px"   /><br />

.aspx.vb:

Protected Sub cmdEncode_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdEncode.Click
 
'Get the String 
Dim convString As String = txtReadScript.Text
'Create a StringWriter object
Dim tw As New System.IO.StringWriter
'Encode the HTML Code
Server.HtmlEncode(convString, tw)
'Decode the HTMLCode
Server.HtmlDecode(convString, tw)
'Display Encoded and Decoded string in MultiLine TextBox Control 
txtMsg.Text = tw.ToString
 
End Sub

Open in new window

LVL 1
megninAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

masterpassCommented:
Is it possible to add another viewing option button to the "Editor" Ajax control to view the page with the HTML "Encoded" so that "<", ">" and " " " show as "<", ">" and "&Quote;"?>>>>>>>>>>>>>

Yes, It is possible since the Ajaxtoolkit is giving you the source. You can download the source from codeplex. But It will be a very difficult task to complete and is going to take more time. So from a feasibility stand point, if your time frame is less, then the answer is NO

The HTML editor is usually built for showing the content as well as its HTML part so as to enable the editing in HTML code too. So I don't even understand the logic why you want it decoded and shown!!!

What I would recommend is not to edit the toolkit source, but you can place another button in your form and when user click on it you can do some javascripting so that the content from the HTML editor is converted in the way you want it and show it in another label or textbox ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
You are calling the

Server.HtmlEncode(convString, tw)
'Decode the HTMLCode
Server.HtmlDecode(convString, tw)

together!

Try this

Protected Sub cmdEncode_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdEncode.Click
       txtMsg.Text = Server.HTMLEncode(txtReadScript.Text)
End Sub
0
megninAuthor Commented:
masterpass, yes, your recommendation will work just fine.  I've gotten a page started that uses an AJAX Edit control for the user to create the layout with and then I copy the html code into a JavaScript textbox to Encode.  The encoded output is needed for a thing like an RSS reader.  It's an XML file that defines a little html web page.
CodeCruiser, oh, thanks, I didn't notice that.  I'm not sure if it is just a "cut and paste mistake" or the source of my problem.  I'll check it out.  Thank you for the new code snippet!
0
megninAuthor Commented:
Thank you both.  I'm sorry I got side tracked from this for so long.  It was for a minor project and then a major one came up.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.