2

I'm currently working on a project that needs HtmlEditorExtender. Recently I faced a weired problem just with the HtmlEditorExtender.
When I type texts and click on button Save. Everything works fine. But When I copy & Paste texts ( short or paragraphs) . The HtmlEditorExtender loses its value, and The data will not be saved. However, I tried the same with regular textboxes. But I didn't find any issue with them. My code looks something like this: Default.aspx:

<asp:UpdatePanel runat="server" ID="id123">
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
<ContentTemplate>

<asp:TextBox ID="txtSlidePage"  TextMode="MultiLine" Columns="50" Rows="10" Width="100%" Height="200" runat="server" />

<ajaxToolkit:HtmlEditorExtender ID="HtmlEditorExtender1" TargetControlID="txtSlidePage"   runat="server" DisplaySourceTab="true">
<Toolbar>
<ajaxToolkit:Undo />
<ajaxToolkit:Redo />
</Toolbar>
</ajaxToolkit:HtmlEditorExtender>

</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1"  />

Code behind:

protected void Button1_Click1(object sender, EventArgs e)
{
Response.Write("<script>alert('" + txtSlidePage.Text + "');</script>");
}

I've kept the code short. just to see the result via Javascript Alert.

Any suggestions?

rebo lavo
  • 179
  • 1
  • 2
  • 13
  • 1
    have you tried a session to store and retrieve the editor content? – reaz Apr 06 '16 at 18:47
  • Yes, but it was the same. As i mentioned , with regular textboxes everything is fine. but with that html editor extender. the content will be reset on the post back when the text is copy and pasted. – rebo lavo Apr 06 '16 at 18:48

1 Answers1

2

I strongly recommend you to use CKEditor. I have been using it without any issues and it has an easy to use control for asp.net. The process of HTML Encoding and Decoding is easy as well. Please refer to this link for demo

You can also easily custom toolbars as shown bellow:

<CKEditor:CKEditorControl ID="txtSlideTexts" BasePath="/ckeditor/" runat="server"  Toolbar="Basic"
    ToolbarBasic="|Bold|Italic|Underline|Strike|-|NumberedList|BulletedList|Outdent|Indent|-|JustifyLeft|JustifyCenter|JustifyRight|JustifyBlock|
    |Link|Unlink|-|TextColor|-|Undo|Redo|Cut|Copy|Paste|PasteText|PasteFromWord|
  |Find|Replace|SelectAll|-|Image|Table|HorizontalRule|SpecialChar|-|Format|" ></CKEditor:CKEditorControl>

And finally in code behind:

string str = CKEditor1.Text;
string str1 = Server.HtmlEncode(str);
string str2 = Server.HtmlDecode(str);

Since it's a server side control. You will not face difficulties during page post back issue.

reaz
  • 735
  • 1
  • 10
  • 20