zoukankan      html  css  js  c++  java
  • AspxhtmlEditor添加自定义按钮

    Aspx代码:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"

        Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>

    <%@ Register Assembly="DevExpress.Web.ASPxHtmlEditor.v11.1, Version=11.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"

        Namespace="DevExpress.Web.ASPxHtmlEditor" TagPrefix="dx" %>

    <%@ Register Assembly="DevExpress.Web.ASPxSpellChecker.v11.1, Version=11.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"

        Namespace="DevExpress.Web.ASPxSpellChecker" TagPrefix="dx" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <title></title>

    </head>

    <script type="text/javascript">

        // <![CDATA[

        var MailMessageTemplate = '<p>Hi,</p><p>Thanks, <br/>Serge<br/><br/>R&amp;D, ASP.Net Team<br/>Developer Express Inc.<br/><br/>PS. If you wish to receive direct assistance from our Support Team, use Support Center at <a target="_blank" href="http://www.devexpress.com/Support/Center">http://www.devexpress.com/Support/Center</a></p>';

        function PasteEmailTemplate(commandName) {

            switch (commandName) {

                case ('deleteall'):

                    HtmlEditor.ExecuteCommand(ASPxClientCommandConsts.SELECT_ALL, null);

                    HtmlEditor.ExecuteCommand(ASPxClientCommandConsts.PASTEHTML_COMMAND, '&nbsp;');

                    alert('fuck');

                    break;

                case ('pastetemplate'):

                    HtmlEditor.ExecuteCommand(ASPxClientCommandConsts.SELECT_ALL, null);

                    HtmlEditor.ExecuteCommand(ASPxClientCommandConsts.PASTEHTML_COMMAND, MailMessageTemplate);

                    break;

            }

        }

    </script>

    <body>

        <form id="form1" runat="server">

        <div>

        </br>

        </br>

            <dx:ASPxHtmlEditor ID="DemoHtmlEditor" runat="server" ClientInstanceName="HtmlEditor">

                <Toolbars>

                    <dx:HtmlEditorToolbar Caption="DemoToolbar" Name="DemoToolbar">

                        <Items>

                            <dx:ToolbarUndoButton>

                            </dx:ToolbarUndoButton>

                            <dx:ToolbarRedoButton>

                            </dx:ToolbarRedoButton>

                            <dx:ToolbarJustifyLeftButton BeginGroup="True">

                            </dx:ToolbarJustifyLeftButton>

                            <dx:ToolbarJustifyCenterButton>

                            </dx:ToolbarJustifyCenterButton>

                            <dx:ToolbarJustifyRightButton>

                            </dx:ToolbarJustifyRightButton>

                            <dx:ToolbarJustifyFullButton>

                            </dx:ToolbarJustifyFullButton>

                            <dx:CustomToolbarButton CommandName="pastetemplate" ToolTip="Paste mail message template"

                                BeginGroup="true">

                                <Image Url="easyicon_cn_48.ico"></Image>

                            </dx:CustomToolbarButton>

                            <dx:CustomToolbarButton CommandName="deleteall" Text="Delete All" ToolTip="Delete all">

                            </dx:CustomToolbarButton>

                        </Items>

                    </dx:HtmlEditorToolbar>

                </Toolbars>

                <ClientSideEvents CustomCommand="function(s, e) { PasteEmailTemplate(e.commandName); }">

                </ClientSideEvents>

            </dx:ASPxHtmlEditor>

            <br />

            <br />

        </div>

        </form>

    </body>

    </html>

     

    1. 在EditorToolBar中添加<dx:CustomToolbarButton CommandName="deleteall" Text="Delete All" ToolTip="Delete all"></dx:CustomToolbarButton> 其中CommandName指定按钮的事件名称(客户端事件,预处理服务器端事件,可以借助ajax思想),Text指定按钮上的文字
    2. 注册事件:在ToolBar后面添加如下代码注册事件

    <ClientSideEvents CustomCommand="function(s, e) { PasteEmailTemplate(e.commandName); }"></ClientSideEvents>

    1. 定义事件:是Javascript的脚本事件

    function PasteEmailTemplate(commandName) {

            switch (commandName) {

                case ('deleteall'):

                    HtmlEditor.ExecuteCommand(ASPxClientCommandConsts.SELECT_ALL, null);//先全选

                    HtmlEditor.ExecuteCommand(ASPxClientCommandConsts.PASTEHTML_COMMAND, '&nbsp;');//替换成&nbsp

                    break;

                case ('pastetemplate'):

                    HtmlEditor.ExecuteCommand(ASPxClientCommandConsts.SELECT_ALL, null);//全选

                    HtmlEditor.ExecuteCommand(ASPxClientCommandConsts.PASTEHTML_COMMAND, MailMessageTemplate);//替换为想要的字。 定义方式:var MailMessageTemplate=”………”(js)

                    break;

            }

        }

  • 相关阅读:
    Leetcode 433.最小基因变化
    穿越牛熊的“巴菲特”投资系统(发布于05-27 11:02)
    巴菲特的“安全边际”(发布于2019-6-16 10:39)
    安全边际:成功的基石(附选股)(选股策略系列五完结篇)(发布于06-14 11:11)
    分红与成长性:投资回报的体现(选股策略系列四)(发布于06-13 13:35)
    合理的资本结构:企业的生命线(选股策略系列2)(发布于06-11 12:44)
    稳定的每股利润:价值的基础(选股策略系列三)(发布于06-12 09:57)
    股票与债券的对比投资(发布于06-09 10:13)
    二类股值得投资吗?(选股策略系列一)(发布于06-10 15:51)
    透视伯克希尔投资组合---看巴菲特与格雷厄姆(发布于06-07 09:43)
  • 原文地址:https://www.cnblogs.com/limingluzhu/p/2255325.html
Copyright © 2011-2022 走看看