Hi,
I'm dynamically generating a number of Textbox and HTMLEditorExtender controls to be added to a webpage through code behind. My goal is that when text/html is modified on the HTMLEditorExtender control that a postback occurs which triggers the text/html to be saved to a database. So far I have this process working using the OnContentChanged event and JavaScript.
However I have ran into quite a big problem with this approach, basically when a postback occurs any formatted/html text is then displayed as actual plain text instead of RichText e.g. if I enter "Hello World!" when a postback occurs this would then be displayed as "<b>Hello World!</b>" which defeats the purpose of having the HTMLEditorExtender in the first place. My code is below:
JavaScript:
<script type="text/javascript" src="../../Scripts/jquery-1.10.2.min.js"></script><script type="text/javascript">
var tbxID;
function onContentChanged() {
alert(tbxID);
//your code do postback.
__doPostBack(tbxID, '');
}
$(function () {
Sys.Application.add_load(function () {$('.ajax__html_editor_extender_texteditor').keyup(function () {
//get the target id if a html_editor_extender keyup
tbxID = $(this).parent().find("textarea").attr("id");
});
});
})</script>Code behind:
protected void Page_Load(object sender, EventArgs e)
{
TextBox tbxElementCustomText = new TextBox();
tbxElementCustomText.TextMode = TextBoxMode.MultiLine;
tbxElementCustomText.Columns = 100;
tbxElementCustomText.Rows = 25;
tbxElementCustomText.AutoPostBack = true;
tbxElementCustomText.ID = "tbxElementCustomText";
this.PlaceHolder1.Controls.Add(tbxElementCustomText);
AjaxControlToolkit.HtmlEditorExtender htmlEditorExtender = new AjaxControlToolkit.HtmlEditorExtender();
htmlEditorExtender.ID = "htmlEditExt";
htmlEditorExtender.TargetControlID = tbxElementCustomText.ID;
htmlEditorExtender.EnableSanitization = false;
htmlEditorExtender.DisplaySourceTab = true;
htmlEditorExtender.OnClientChange = "onContentChanged";
this.PlaceHolder1.Controls.Add(htmlEditorExtender);
}If anyone knows of a solution so that the RichText is kept within the HTMLEditorExtender when a postback occurs it would be much appreciated.
Many thanks,
Daniel