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;

            }

        }

  • 相关阅读:
    Simple Automated Backups for MongoDB Replica Sets
    [转] matlab获取时间日期
    Matlab与C++混合编程 编写独立外部应用程序时出现“无法定位序数3906于动态链接库LIBEAY32.dll上”错误
    Visual Studio 控制台应用程序 同时使用OpenCV和matlab mat文件操作
    [转] Matlab与C++混合编程(依赖OpenCV)
    OpenCV 64位时 应用程序无法正常启动0x000007b 问题解决
    LinkedBlockingQueue多线程测试
    rdlc报告vs2008编辑正常,在vs2012在对错误的编辑
    SD3.0四个协议解读
    链队列
  • 原文地址:https://www.cnblogs.com/limingluzhu/p/2255325.html
Copyright © 2011-2022 走看看