• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1116
  • Last Modified:

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

0
megnin
Asked:
megnin
  • 2
2 Solutions
 
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
 
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
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now