0

I am trying to display my blog content that is stored in my database in the form of raw html tags and img tags. I tried using HTML Encode before inserting data in the database and Decode while retrieving the data. After doing so I am getting an output like this.

enter image description here

I want to get an output like thisenter image description here

I tried doing this but nothing worked

//code to put this text into the database
string text = Server.HTMLEncode(userEnteredText);

//code to put while fetching data from DB
string text = Server.HTMLDecode(userEnteredText);

Please note I am using Webforms and not MVC framework

I would be obliged if anyone could help me with this.

11
  • What happens when you do not use string text = Server.HTMLDecode(userEnteredText); Can you please check. Commented Dec 12, 2014 at 13:08
  • What kind of server control are you using to display the output? Commented Dec 12, 2014 at 13:11
  • @BenRobinson I am using a Label to display my output Commented Dec 12, 2014 at 13:40
  • @Amit as mentioned above I am getting the output shown in the second image Commented Dec 12, 2014 at 13:41
  • That is probably your problem then. A Label will automatically HTML encode what is set in the Text property before rendering to the browser. Use a Literal instead. Commented Dec 12, 2014 at 13:43

1 Answer 1

1

You should try LiteralControl

With this you can inject Html into your page at runtime like so:

this.Controls.Add("<h1>Hello World</h1>");
this.Controls.Add(userEnteredText);

Further reading:

//EDIT:

Take an Water bottle

Is wrong from my little understanding of the English language. It should be "Take a water bottle" A is only attached with the suffix n in case the next word starts with a vowel (a, e, i, o, u).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your quick response I tried using Literal control earlier but it dint seem to work.I'll try using the reference you have mentioned above and see if that does the trick

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.