Try our conversational search powered by Generative AI!

Server.HTMLEncode for a property

Vote:
 

Hi!

Is there a way to use HTMLEncode like this?
<%= Server.HTMLEncode("<EPiServer:Property runat="server" PropertyName="text" ID="text" />") %>

What I want to do is find a way to convert åäö ÅÄÖ to html-code for the text that editors write in an XHTML edit box. Maybe there is another way?

The problem I have is that I'am working on a newsletter template, the editor work with it and then, in IE, use the "Send page as mail" function. But the swedish characters get messed up (I have tried different charset) in Outlook.

Thanks!

#52503
Aug 01, 2011 8:33
Vote:
 

You can't do text processing on a control like that, but you shouldn't need to since the property control will output the xhtml from the editor which should already be encoded. Does the html source of the rendered page seem to be encoded correctly if you view it in the browser?

#52504
Aug 01, 2011 9:07
Vote:
 

Hi! Thanks for the reply.

No the swedish characters (from the xhtml box) does not get encoded when I view the source in IE.

#52506
Edited, Aug 01, 2011 9:22
Vote:
 

I was so sure the editor encoded the chars, but I tried it now and it doesn't. The problem is you can't do htmlencode on the whole xhtml-property because you will also encode the HTML and see "<p>" etc in the output whilst losing the formating information.

What you need to get tinyMCE to encode the chars is to set its init option "entity_encoding" to "numeric". There is probably a simpler way to do this, but the only thing I can think of is to create a plugin for tinyMCE which does this.

Do it by creating a class and decorating it with the EPiServer.Editor.TinyMCE.TinyMCEPluginNonVisual attribute where you specify the option. I uploaded a code sample: http://world.episerver.com/Code/Magnus-Rahl-ne-Paulsson/Enable-special-character-encoding-in-Tiny-MCE/

As noted there I don't know the side effects.

#52514
Edited, Aug 01, 2011 10:40
Vote:
 

Hi!

Thank you very much. It sounds too risky however, sorry. Can I do something in the code behind file for the page template?

#52533
Aug 02, 2011 8:34
Vote:
 

Sorry, I can't think of any good/easy/fast way to do it. Since the property data contains html you would have to parse/search and replace it since you can't encode it as a whole...

#52538
Aug 02, 2011 9:32
Vote:
 

Hm ok, thank you! It just seems a bit strange that this problem hasnt come up before (or maybe it has). Is it so far fetched to be able to develop an Epi template that an editor can use to make a newsletter page and then send it via Outlook.

Iam not blaiming epi here though. We had a newsletter before that we coded in html in notepad+, we had to encode åäö etc for it to display properly in outlook. So I guess the same thing applys when a page is done in Epi. But is there no way around it?

Can I build something so the webserver sends the mail with all the images?

#52611
Aug 05, 2011 8:28
Vote:
 

Hi Henrik,

 

I think in the code behind while saving the content it is saved in Encoded format as a result when the page is fetched again the encoded text is binded to the page. By saying this I mean that somewhere while setting the property in the code behind file you might have coded as Server.HTMLEncode(XHTML edtor control.Text). So the encoded content is published in the page .

Regards,

S.K. SreeRaghavendra

#52635
Aug 08, 2011 9:03
Vote:
 

Sreeraghavendra SK: Thank you, but I dont really understand, sorry. Iam rather new to this.

I did some testing however. Just created an ordinary html file in my project and gave it meta charset=utf-8, and saved it with Unicode (UTF-8 without signature) - Codepage 65001, the page has some swedish characters in a p tag. The page is displayed fine in Outlook! But when I do the same with my masterpage and the one and only template it wont work - the swedish characters get messed up in Outlook.

#52695
Aug 10, 2011 10:15
Vote:
 

Hi Henrik,

In the code behind file of your page where the contents are being added.... Say your content field control's name is "txtContent" are you saving the content into the page as Server.HTMLEncode(txtContent.Text)?

Regards,

S.K. SreeRaghavendra

 

#52699
Aug 10, 2011 11:00
Vote:
 

Hi Sreeraghavendra SK.

Hm, I didnt write any code behind in particular for that aspx page. I thougt it would be enough to just write the <%= Server.HTMLEncode() %> in the aspx file? Maybe not though? He he. As I said, Iam rather new to this.


Here is the actual example by the way.

# In the aspx file, NewsLetterCulturumStart.aspx,  I have a property, it looks like this:
<EPiServer:Property runat="server" PropertyName="teaterText" ID="teaterText" /> in edit mode it is a xhtml edit box.

# The code behind file, NewsLetterCulturumStart.aspx.cs, have this code (wich I believe is the default code for a newly created template):
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.Web.WebControls;

namespace NYK.NewsLetter.Pages
{
    public partial class NewsLetterCulturumStart : EPiServer.TemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
    }
}

 

One question I have! To use the code <%= Server.HTMLEncode() %> in the aspx file (for anything) you have to write code behind code? Very important question! Because I thougnt that <% ... %> meant that it was enough to have the code in the aspx file only. Like this for instance worked fine, just in the aspx file:

<% if(CurrentPage.LanguageBranch.ToString()=="sv"){ %>

<% } else { %>

<% } %>

 

Thank you very much and maybe we can take it from here. =)

#52700
Edited, Aug 10, 2011 11:22
Vote:
 

Hi Henrik,

You can also add the HTMLEncode text in the aspx page as well. you can add it as:

 

<%=HttpContext.Current.Server.HtmlEncode("some string text")%>

 

But in case you want the swedish alphabets to get displayed as it is instead of the encoded values.... you need to use Server.HtmlDecode instead of HtmlEncode.

 

Hope this helps. :)

Regards,

S.K. SreeRaghavendra



 

 

 

#52704
Aug 10, 2011 12:13
Vote:
 

Hi Sreeraghavendra SK! Ok thank you. Yeah I tried

<%=HttpContext.Current.Server.HtmlEncode("some string text")%>

with ÅÄÖ åäö in the string and the source code displayed their code: &#197; &#196; &#214; &#229; &#228; &#246;

So, wouldnt it be far fetched to be able to use this thing to make every "swedish character" (ÅÄÖ åäö) to get converted to the respective code? Is it something I can do in the code behind file, you think?

I see that you mention I should use decode instead of encode, why?

For fun I tested <%=HttpContext.Current.Server.HtmlDecode("&#197")%> and I had expected a Å in the source code for the page but no, just &#197.

But anyway, some how, in the code behind file, you have a solution so every swedish character get coded in the unicode(?) numbers - thus will be displayed correctly in outlook?

#52708
Edited, Aug 10, 2011 13:11
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.