WebHtmlEditor™ features several drop-down list boxes on its standard toolbar. These drop-down lists support being populated with custom list items. See the topic, Toolbar Drop-Downs Lists for a list of these drop-down lists. This topic also describes common approaches to how you can populate different types of drop-down lists with your own items. The information in this topic applies fairly evenly to all drop-down and custom lists.
WebHtmlEditor provides list-typed properties for several of the toolbar drop-down lists (as shown below).
In the walkthrough, Using the WebHtmlEditor Designer, you learned how to use the properties dialog box when adding fixed items to the FontStyleList (or any of the other list objects) at design time. However, if you need items that respond to more dynamic circumstances (such as a list of the current user’s favorite styles), then you must populate items into the lists at run time, as in the following example.
In Visual Basic:
Imports Infragistics.WebUI.WebHtmlEditor ... Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.Load If( Not Page.IsPostBack ) Then ' Add a custom style to FontStyleList using a CSS style definition. Me.WebHtmlEditor1.FontStyleList.Add( "strikeout", _ "color: red; text-decoration: line-through;") End If End Sub
In C#:
using Infragistics.WebUI.WebHtmlEditor; ... private void Page_Load( object sender, System.EventArgs e) { if( !Page.IsPostBack) { // Add a custom style to FontStyleList using a CSS style definition. this.WebHtmlEditor1.FontStyleList.Add( "strikeout", "color:red; text-decoration:line-through;"); } }
Another example of a custom list with a toolbar drop-down list is the Insert list, which contains several items (e.g., "Greeting" and "Signature"). When the user selects one of these items, text is inserted at the current caret position within the document.
Suppose your Web application let users create content for regulatory documents and you want to make a library of boilerplate text passages available (such as the customary disclaimer of forward-looking statements commonly found in the press releases of public companies.) Users should be able to select these predefined text passages by a short, descriptive name to save themselves some typing.
Adding these custom items to the Insert Toolbar drop-down list requires you to create (name, value) pairs as ToolbarDropDownItem objects, and then add them to the Toolbar drop-down list during the PreRender event of the Page, as shown in the example below.
In Visual Basic:
Private Sub Page_PreRender(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.PreRender If( Not Page.IsPostBack ) Then Dim dropDown As ToolbarDropDown ' Find the Insert drop down item in the Toolbar.Items collection. dropDown = CType( _ Me.WebHtmlEditor1.Toolbar.Items.GetByType(ToolbarItemType.Insert), ToolbarDropDown) ' Add standard disclaimer for correspondence to Insert drop down. dropDown.Items.Add( New ToolbarDropDownItem( _ "Disclaimer", _ "THIS MESSAGE IS PROVIDED AS IS WITHOUT" + _ " WARRANTY OR GUARANTEE FOR ANY PURPOSE." ) ) End If End Sub
In C#:
private void Page_PreRender( object sender, System.EventArgs e) { if ( !Page.IsPostBack) { // Find the Insert drop down item in the Toolbar.Items collection. ToolbarDropDown dropDown = (ToolbarDropDown) this.WebHtmlEditor1.Toolbar.Items.GetByType( ToolbarItemType.Insert); // Add standard disclaimer for correspondence to Insert drop down. dropDown.Items.Add( new ToolbarDropDownItem( "Disclaimer", "THIS MESSAGE IS PROVIDED AS IS WITHOUT " + "WARRANTY OR GUARANTEE FOR ANY PURPOSE." ) ); } } . . . private void InitializeComponent() { // Handle the Page.PreRender event. this.PreRender += new System.EventHandler(this.Page_PreRender); }
The following table summarizes the conditions when it is best to use each practice.