Hi srp10,
Please test the example below, it shows you how to add a custom button into toolbar of editor and change the selected text to you own format by this button.
- <%@ Page Language="C#" %>
-
- <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
- <script runat="server">
- protected override void OnLoad(EventArgs e)
- {
-
- CuteEditor.ToolControl tc = Editor1.ToolControls["insertcustombutonhere"];
- if (tc != null)
- {
- System.Web.UI.WebControls.Image Image1 = new System.Web.UI.WebControls.Image();
- Image1.ToolTip = "Insert today's date";
- Image1.ImageUrl = "tools.gif";
- Image1.CssClass = "CuteEditorButton";
- Image1.Attributes["onclick"] = "changeText()";
- tc.Control.Controls.Add(Image1);
- }
- base.OnLoad(e);
- }
- </script>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Untitled Page</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <CE:Editor ID="Editor1" runat="server" >
- </CE:Editor>
- </div>
- </form>
- </body>
- </html>
- <script>
-
- function getSelectedHTML(){
- var editor1=document.getElementById("<%= Editor1.ClientID %>");
-
- var editwin = editor1.GetWindow();
-
-
-
- var editdoc = editor1.GetDocument();
-
- var rng=null,html="";
- if (document.selection && document.selection.createRange){
- rng=editdoc.selection.createRange();
- html=rng.htmlText||"";
- }else if (window.getSelection){
- rng=editwin.getSelection();
-
- if (rng.rangeCount > 0 && window.XMLSerializer){
- rng=rng.getRangeAt(0);
- html=new XMLSerializer().serializeToString(rng.cloneContents());
- }
- }
- return html;
- }
-
- function changeText()
- {
- var editor1=document.getElementById("<%= Editor1.ClientID %>");
- editor1.PasteHTML("$"+getSelectedHTML());
- }
-
- </script>
Regards,
Ken