0

I am using textarea. This Textarea functionality is similar to Rich Text Box. My textarea has

<div style="width:100px;"><div style="height="400px;"></div></div>

In button click event I want to save this text in database table. But my coding saved like this

<div><div></div></div>
1
  • 1
    you have to use htmlencode class before saving to db Commented Jun 25, 2013 at 12:08

1 Answer 1

1

Problem is you have to encode your code

using System;
using System.Net;

class Program
{
    static void Main()
    {
    string a = WebUtility.HtmlEncode("<html><head><title>T</title></head></html>");
    string b = WebUtility.HtmlDecode(a);

    Console.WriteLine("After HtmlEncode: " + a);
    Console.WriteLine("After HtmlDecode: " + b);
    }
}

output

After HtmlEncode:

&lt;html&gt;&lt;head&gt;&lt;title&gt;T&lt;/title&gt;&lt;/head&gt;&lt;/html&gt;

further read these articles

http://stackoverflow.com/questions/1144535/htmlencode-from-class-library

and

http://msdn.microsoft.com/en-us/library/w3te6wfz.aspx

and

http://www.dotnetperls.com/htmlencode-htmldecode 
Sign up to request clarification or add additional context in comments.

3 Comments

I am using html decoding only.But inside the div tag i am using style attribute inside div tag style="width:100px;".That one was not saving into database table.
<div style="width:100px;"><div style="height="400px;"></div></div> after html decoding i am getting like this <div><div></div></div>
flag a breakpoint and debug then let me know second use tinymice or ajaxhtml editor dont use textarea

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.