Re: Numeric or Currency formatting

  •  01-17-2011, 7:36 PM

    Re: Numeric or Currency formatting

    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.
     
    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    5.   
    6. <script runat="server">  
    7.     protected override void OnLoad(EventArgs e)  
    8.     {  
    9.         //add custom button into the toolbar  
    10.         CuteEditor.ToolControl tc = Editor1.ToolControls["insertcustombutonhere"];  
    11.         if (tc != null)   
    12.         {   
    13.             System.Web.UI.WebControls.Image Image1 = new System.Web.UI.WebControls.Image();   
    14.             Image1.ToolTip = "Insert today's date";  
    15.             Image1.ImageUrl = "tools.gif";  
    16.             Image1.CssClass = "CuteEditorButton";  
    17.             Image1.Attributes["onclick"] = "changeText()";  
    18.             tc.Control.Controls.Add(Image1);  
    19.         }  
    20.         base.OnLoad(e);  
    21.     }  
    22. </script>  
    23.   
    24. <html xmlns="http://www.w3.org/1999/xhtml">  
    25. <head runat="server">  
    26.     <title>Untitled Page</title>  
    27. </head>  
    28. <body>  
    29.     <form id="form1" runat="server">  
    30.         <div>  
    31.             <CE:Editor ID="Editor1" runat="server" >  
    32.             </CE:Editor>  
    33.         </div>  
    34.     </form>  
    35. </body>  
    36. </html>  
    37. <script>  
    38. //get the selected text of editor  
    39. function getSelectedHTML(){  
    40.       var editor1=document.getElementById("<%= Editor1.ClientID %>");  
    41.       // get the active editor window  
    42.       var editwin = editor1.GetWindow();  
    43.   
    44.   
    45.       // get the active editor document  
    46.       var editdoc = editor1.GetDocument();  
    47.   
    48.       var rng=null,html="";   
    49.       if (document.selection && document.selection.createRange){  
    50.         rng=editdoc.selection.createRange();  
    51.         html=rng.htmlText||"";  
    52.       }else if (window.getSelection){  
    53.         rng=editwin.getSelection();  
    54.   
    55.         if (rng.rangeCount > 0 && window.XMLSerializer){  
    56.           rng=rng.getRangeAt(0);  
    57.           html=new XMLSerializer().serializeToString(rng.cloneContents());  
    58.         }  
    59.       }  
    60.       return html;  
    61.  }  
    62.  //change the selected text to the format you need  
    63.  function changeText()  
    64.  {  
    65.     var editor1=document.getElementById("<%= Editor1.ClientID %>");  
    66.     editor1.PasteHTML("$"+getSelectedHTML());  
    67.  }  
    68.   
    69. </script> 
     
    Regards,
     
    Ken
View Complete Thread