Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4086732
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:45:54+00:00 2026-05-20T18:45:54+00:00

What follows is a piece of text that gets HtmlEncoded in C# before being

  • 0

What follows is a piece of text that gets HtmlEncoded in C# before being sent to the browser (during a callback). Once received, in Javascript I do myDiv.innerHTML = theStringBelow;

<span xmlns:asp="http://schemas.microsoft.com/ASPNET/20" 
      xmlns:SharePoint="Microsoft.Sharepoint.WebControls"
      xmlns:ext="my_namespace:my_xslt_extension">Some text to be shown.</span>

However, what results is that I simply see the exact text shown above. It isn’t being treated as an html element that got added to the DOM, but as plain text. When I add the exact same text through javascript (e.g., I skip the callback, and just say myDiv="exactString“) it DOES get added correctly (it gets treated as a span).

What is going on? Do I have to un-encode it? Should I not have encoded to begin with?

Edit
The question still stands for curiosity’s sake, but I have fixed the issue simply by not HtmlEncoding the data. An earlier issue must have added onto this one, making me think the HtmlEncoding was still necessary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:45:55+00:00Added an answer on May 20, 2026 at 6:45 pm

    You should not HTMLEncode it if it is to become HTML nodes. What HTML encoding will do is turn your string from above into this:

    &lt;span xmlns:asp="http://schemas.microsoft.com/ASPNET/20" 
      xmlns:SharePoint="Microsoft.Sharepoint.WebControls"
      xmlns:ext="my_namespace:my_xslt_extension"&gt;Some text to be shown.&lt;/span&gt;
    

    Try passing the string in as it is. You will of course have to escape the string. But once it has become a string in JavaScript it should be unescaped as it is being made into a string in memory. Then you should be able to do the div.innerHTML call and get your expected result. The escaping of the string can probably be accomplished by doing the following:

    // in your .cs code-behind/view/whatever.
    string = string.replace("""", "\""");
    

    Which should produce:

    <span xmlns:asp=\"http://schemas.microsoft.com/ASPNET/20\" 
      xmlns:SharePoint=\"Microsoft.Sharepoint.WebControls\"
      xmlns:ext=\"my_namespace:my_xslt_extension\">Some text to be shown.</span>
    

    Which you can then output like so:

    // in your webform/view
    <script type="text/javascript">
      var mystring;
      mystring = "<%=string;%>";
    </script>
    

    Let me know how that works out for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of javascript code as follows: var data = { ...
My problem is as it follows: I have a piece of JavaScript code which
I have a piece of text, that I wish to show truncated, but when
Im trying to grab a piece of data on a line that follows a
I saw a piece of Scala code with manifest syntax as follows. I do
My issue is as follows. We have dict that has all keys and values
Good day! There is a problem: Selected piece of text. In the allocation is
In my models I often use text fields that are intended to contain large
The following piece of code starts a process that takes one second to finish,
I have a piece of code that counts from 0 to a specified number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.