This article will talk specifically about how to add a Rich Text Editor to your custom application pages. When initially doing some research on this topic, I found a lot of information, but not anything useful that I could actually implement. Here are my steps for adding a control of this type to your pages:
- If you would like to leverage the default sharepoint rich text editor control within your own custom pages, there’s one class you need to get familiar with: InputFormTextBox
- The actual MSDN reference is not very helpful so to get started with a control of this type, you’ll need to know a couple things. Let’s begin by adding the control to our page as follows:
<wssawc:InputFormTextBox ID="iftxtDescription" runat="server" TextMode="MultiLine" Rows="20" RichTextMode="FullHtml" RichText="true"></wssawc:InputFormTextBox>
- The reason I know it’s wssawc is because at the top of the custom application page, Microsoft.SharePoint.WebControls namespace should be registered with a tagprefix of wssawc:
<%@ Register TagPrefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=188.8.131.52, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
- Some properties to be aware of:
- ID – all controls need this. You’ll use the ID to work with the control in the code behind or the inline code
- TextMode – this specifies whether the control is a Password control, a MultiLine control or SingleLine control. If youâ€™re attempting to create a rich text editor, you’ll want to set this to MultiLine.
- Rows – specifies the rows/height of this control
- RichTextMode – specifies whether the mode for the rich text. Options are: Compatible, FullHtml, HtmlAsXml.
- RichText – true or false. Don’t forget to set this to true!
- To save data from this type of control:
calendarListItem["Job Description"] = iftxtDescription.Text;
- To read data from a rich text column into this control:
SPFieldMultiLineText multiDescription = (SPFieldMultiLineText)listItem.Fields["Job Description"]; iftxtDescription.Text = multiDescription.GetFieldValueForEdit(listItem["Job Description"]);
That should do it! I should point out that the multiDescription object that we created above actually has a couple useful methods beyond the one that I used. GetFieldValueForEdit() will grab the contents of the field in rich text and display it in my control quite nicely. I could also have used GetFieldValueAsHTML() for html or GetFieldValueAsText() for plain text.
Note: If you attempt to set the Enabled or ReadOnly properties of this control, they won’t work. I ran into this issue myself and confirmed it with several other users having the same problem. Microsoft has acknowledged this as a bug (37846) but I have yet to find any documentation on this bug. If you do find anything, please let me know!