Bhavana says:
Hi,
I am working on a multi language website(English and Vietnamese). I am using CKEditor in my content management system. While updating the Vietnamese contents, the text is changed to soem wiered symbols.
Anybody here knows the reason? Pls help
Check the DataType in Database if its VARCHAR type then changes it to NVARCHAR also at time of saving use Server.HtmlDecode. Refere the below sample code for your reference.
HTML
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ckEditor</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CKEditor:CKEditorControl ID="CKEditor1" BasePath="/ckeditor/" runat="server"></CKEditor:CKEditorControl>
</div>
<div>
<asp:Button ID="Button2" Text="Save" runat="server" OnClick="Save" />
</div>
</form>
</body>
</html>
C#
protected void Save(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO DocTable([Desc],Desc1) VALUES(@Desc,@Desc1)", con))
{
cmd.Parameters.AddWithValue("@Desc", Server.HtmlDecode(CKEditor1.Text));
cmd.Parameters.AddWithValue("@Desc1", Server.HtmlDecode(CKEditor1.Text));
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
SQL
CREATE TABLE [DocTable](
[id] [int] IDENTITY(1,1) NOT NULL,
[Desc] [nvarchar](100) NULL,
[DESC1] [varchar](100) NULL
) ON [PRIMARY]
Screenshot