user1240045
user1240045

Reputation: 99

How to save HTML Tags and its attributes in sql table?

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>

Upvotes: 0

Views: 2242

Answers (1)

skhurams
skhurams

Reputation: 2145

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 

Upvotes: 1

Related Questions