I'm just starting to get to grips with web development and trying to build up some experience. I am implementing the HtmlEditorExtender in my website. I have added all the files and references necessary to use this control and I've got the control displaying correctly. The problem I'm having is I don't seem to be able to get the content of the textbox after making changes. I have attached the control to a textbox, then populated the textbox with the content I wish to edit. Once I've made changes I have a save button that will save the current content in the HTML editor. What I'm seeing is that the Text property of the Textbox is exactly the same as before I made the changes. Is there something obvious that I'm missing.
Code is below:
Markup in UserControl:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Panel ID="pnlPopup" runat="server" Style="display: none" CssClass="modalPopup">
<asp:Panel ID="Panel3" runat="server" Style="background-color: #DDDDDD; border: solid 1px Gray;
color: Black;">
<p>
Edit:
</p>
</asp:Panel>
<asp:TextBox runat="server" ID="txtHTMLContent" CssClass="WhiteTextBox" TextMode="MultiLine"
Columns="50" Rows="10" />
<br />
<ajaxToolkit:HtmlEditorExtender ID="htmlEditor" TargetControlID="txtHTMLContent" Runat="server" EnableSanitization="false" />
<center>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</center>
</asp:Panel>
Code-behind:
protected void Page_Load(object sender, EventArgs e)
{
string content = GetContent();
txtHTMLContent.Text = content;
}
protected void btnSave_Click(object sender, EventArgs e)
{
DatabaseManager dm = new DatabaseManager();
dm.UpdateContent(txtHTMLContent.Text);
}
I would appreciate any help.
wrap txtHTMLContent initialization code in the Page_Load method in if(!IsPostback)
check:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string content = GetContent();
txtHTMLContent.Text = content;
}
}