How to: Implement a popup window from which users can select templates
- 3 minutes to read
In this example, a user opens the popup window to select a template from the predefined list of text templates. ASPxHtmlEditor inserts the selected template at the beginning of its text. The example uses the client-side GetSelectedItems method to get the selected item’s text.
See Also:
ASPxHTMLEditorDemos: Client-Side Functionality
How to show the ASPxPopupControl
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server" ClientInstanceName="htmlEditor">
<Toolbars>
<dx:StandardToolbar1>
<Items>
<dx:ToolbarCutButton>
</dx:ToolbarCutButton>
<dx:ToolbarCopyButton>
</dx:ToolbarCopyButton>
<dx:ToolbarPasteButton>
</dx:ToolbarPasteButton>
<dx:ToolbarPasteFromWordButton>
</dx:ToolbarPasteFromWordButton>
<dx:ToolbarUndoButton BeginGroup="True">
</dx:ToolbarUndoButton>
<dx:ToolbarRedoButton>
</dx:ToolbarRedoButton>
<dx:ToolbarRemoveFormatButton BeginGroup="True">
</dx:ToolbarRemoveFormatButton>
<dx:ToolbarSuperscriptButton BeginGroup="True">
</dx:ToolbarSuperscriptButton>
<dx:ToolbarSubscriptButton>
</dx:ToolbarSubscriptButton>
<dx:ToolbarInsertOrderedListButton BeginGroup="True">
</dx:ToolbarInsertOrderedListButton>
<dx:ToolbarInsertUnorderedListButton>
</dx:ToolbarInsertUnorderedListButton>
<dx:ToolbarIndentButton BeginGroup="True">
</dx:ToolbarIndentButton>
<dx:ToolbarOutdentButton>
</dx:ToolbarOutdentButton>
<dx:ToolbarInsertLinkDialogButton BeginGroup="True">
</dx:ToolbarInsertLinkDialogButton>
<dx:ToolbarUnlinkButton>
</dx:ToolbarUnlinkButton>
<dx:ToolbarInsertImageDialogButton>
</dx:ToolbarInsertImageDialogButton>
<dx:ToolbarCheckSpellingButton BeginGroup="True">
</dx:ToolbarCheckSpellingButton>
<dx:ToolbarTableOperationsDropDownButton BeginGroup="True">
<Items>
<dx:ToolbarInsertTableDialogButton BeginGroup="True" ViewStyle="ImageAndText">
</dx:ToolbarInsertTableDialogButton>
<dx:ToolbarTablePropertiesDialogButton BeginGroup="True">
</dx:ToolbarTablePropertiesDialogButton>
<dx:ToolbarTableRowPropertiesDialogButton>
</dx:ToolbarTableRowPropertiesDialogButton>
<dx:ToolbarTableColumnPropertiesDialogButton>
</dx:ToolbarTableColumnPropertiesDialogButton>
<dx:ToolbarTableCellPropertiesDialogButton>
</dx:ToolbarTableCellPropertiesDialogButton>
<dx:ToolbarInsertTableRowAboveButton BeginGroup="True">
</dx:ToolbarInsertTableRowAboveButton>
<dx:ToolbarInsertTableRowBelowButton>
</dx:ToolbarInsertTableRowBelowButton>
<dx:ToolbarInsertTableColumnToLeftButton>
</dx:ToolbarInsertTableColumnToLeftButton>
<dx:ToolbarInsertTableColumnToRightButton>
</dx:ToolbarInsertTableColumnToRightButton>
<dx:ToolbarSplitTableCellHorizontallyButton BeginGroup="True">
</dx:ToolbarSplitTableCellHorizontallyButton>
<dx:ToolbarSplitTableCellVerticallyButton>
</dx:ToolbarSplitTableCellVerticallyButton>
<dx:ToolbarMergeTableCellRightButton>
</dx:ToolbarMergeTableCellRightButton>
<dx:ToolbarMergeTableCellDownButton>
</dx:ToolbarMergeTableCellDownButton>
<dx:ToolbarDeleteTableButton BeginGroup="True">
</dx:ToolbarDeleteTableButton>
<dx:ToolbarDeleteTableRowButton>
</dx:ToolbarDeleteTableRowButton>
<dx:ToolbarDeleteTableColumnButton>
</dx:ToolbarDeleteTableColumnButton>
</Items>
</dx:ToolbarTableOperationsDropDownButton>
</Items>
</dx:StandardToolbar1>
<dx:StandardToolbar2>
<Items>
<dx:ToolbarParagraphFormattingEdit Width="120px">
<Items>
<dx:ToolbarListEditItem Text="Normal" Value="p" />
<dx:ToolbarListEditItem Text="Heading 1" Value="h1" />
<dx:ToolbarListEditItem Text="Heading 2" Value="h2" />
<dx:ToolbarListEditItem Text="Heading 3" Value="h3" />
<dx:ToolbarListEditItem Text="Heading 4" Value="h4" />
<dx:ToolbarListEditItem Text="Heading 5" Value="h5" />
<dx:ToolbarListEditItem Text="Heading 6" Value="h6" />
<dx:ToolbarListEditItem Text="Address" Value="address" />
<dx:ToolbarListEditItem Text="Normal (DIV)" Value="div" />
</Items>
</dx:ToolbarParagraphFormattingEdit>
<dx:ToolbarFontNameEdit>
<Items>
<dx:ToolbarListEditItem Text="Times New Roman" Value="Times New Roman" />
<dx:ToolbarListEditItem Text="Tahoma" Value="Tahoma" />
<dx:ToolbarListEditItem Text="Verdana" Value="Verdana" />
<dx:ToolbarListEditItem Text="Arial" Value="Arial" />
<dx:ToolbarListEditItem Text="MS Sans Serif" Value="MS Sans Serif" />
<dx:ToolbarListEditItem Text="Courier" Value="Courier" />
</Items>
</dx:ToolbarFontNameEdit>
<dx:ToolbarFontSizeEdit>
<Items>
<dx:ToolbarListEditItem Text="1 (8pt)" Value="1" />
<dx:ToolbarListEditItem Text="2 (10pt)" Value="2" />
<dx:ToolbarListEditItem Text="3 (12pt)" Value="3" />
<dx:ToolbarListEditItem Text="4 (14pt)" Value="4" />
<dx:ToolbarListEditItem Text="5 (18pt)" Value="5" />
<dx:ToolbarListEditItem Text="6 (24pt)" Value="6" />
<dx:ToolbarListEditItem Text="7 (36pt)" Value="7" />
</Items>
</dx:ToolbarFontSizeEdit>
<dx:ToolbarBoldButton BeginGroup="True">
</dx:ToolbarBoldButton>
<dx:ToolbarItalicButton>
</dx:ToolbarItalicButton>
<dx:ToolbarUnderlineButton>
</dx:ToolbarUnderlineButton>
<dx:ToolbarStrikethroughButton>
</dx:ToolbarStrikethroughButton>
<dx:ToolbarJustifyLeftButton BeginGroup="True">
</dx:ToolbarJustifyLeftButton>
<dx:ToolbarJustifyCenterButton>
</dx:ToolbarJustifyCenterButton>
<dx:ToolbarJustifyRightButton>
</dx:ToolbarJustifyRightButton>
<dx:ToolbarJustifyFullButton>
</dx:ToolbarJustifyFullButton>
<dx:ToolbarBackColorButton BeginGroup="True">
</dx:ToolbarBackColorButton>
<dx:ToolbarFontColorButton>
</dx:ToolbarFontColorButton>
</Items>
</dx:StandardToolbar2>
<dx:CustomToolbar>
<Items>
<dx:CustomToolbarButton CommandName="CustomInsertText" Text="Insert Signature">
</dx:CustomToolbarButton>
</Items>
</dx:CustomToolbar>
</Toolbars>
<ClientSideEvents CustomCommand="function(s, e) {
if(e.commandName == 'CustomInsertText') {
popupSignature.Show();
}
}" />
</dx:ASPxHtmlEditor>
<dx:ASPxPopupControl ID="ASPxPopupControl1" runat="server" ClientInstanceName="popupSignature"
Modal="true" CloseAction="CloseButton" HeaderText="Select signature" PopupVerticalAlign="WindowCenter" PopupHorizontalAlign="WindowCenter">
<ContentCollection>
<dx:PopupControlContentControl runat="server">
<table width="300px"><tr><td colspan="2">
<dx:ASPxListBox ID="ASPxListBox1" runat="server" ClientInstanceName="listSignature" Width="100%" SelectedIndex="0">
<Items>
<dx:ListEditItem Text="Yours sincerely," Value="Yours sincerely," />
<dx:ListEditItem Text="Best regards," Value="Best regards," />
<dx:ListEditItem Text="Thank you," Value="Thank you," />
</Items>
</dx:ASPxListBox>
</td></tr>
<tr><td>
<dx:ASPxButton ID="btnInsert" runat="server" Text="Insert" AutoPostBack="false">
<ClientSideEvents Click="function(s, e) {
var templateText = listSignature.GetSelectedItem().text;
popupSignature.Hide();
htmlEditor.ExecuteCommand(ASPxClientCommandConsts.PASTEHTML_COMMAND, templateText);
}" />
</dx:ASPxButton></td><td>
<dx:ASPxButton ID="btnCancel" runat="server" Text="Cancel" AutoPostBack="false" ClientSideEvents-Click="function(s, e) { popupSignature.Hide(); }">
<ClientSideEvents Click="function(s, e) { popupSignature.Hide(); }"></ClientSideEvents>
</dx:ASPxButton>
</table>
</dx:PopupControlContentControl>
</ContentCollection>
</dx:ASPxPopupControl>