2

I have a dim which contains html encoded code, which is stored in DB.

How can I insert the code into asp.net page?
I would like to perform the action in code behind ( VB.net / C# ).

What control/method should I use. Please note I want the code to be rendered by the browsers – not just displayed.

1
  • are you looking for HttpUtility.HtmlDecode and HttpUtility.HtmlEncode methods? what exactly is stored in your DB? Commented Nov 7, 2012 at 9:27

1 Answer 1

3

Assuming web forms, you can use a Literal control on your web page and set its Mode property to PassThrough.

PassThrough meaning

The contents of the control are not modified.

as opposed to the default Transform

The contents of the control are converted to an HTML-encoded string.

Example aspx:

<asp:Literal ID="Literal1" Mode="PassThrough" runat="server"></asp:Literal>

Code-behind:

Me.Literal1.Text = "<p>I'm a paragraph.</p>"
Sign up to request clarification or add additional context in comments.

1 Comment

I edited the answer to include the definition of PassThrough and Transform. Check out the linked msdn documentation, there are even more details and examples.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.