locked
HTMLEditor & Disabling Options RRS feed

  • Question

  • User1658625817 posted

    Is is possible to disable certain features of the HTMLEditor control?  I want to disallow users from changing the font-family or font size and force them to use my own default family/size. 

    Tuesday, December 1, 2009 2:24 PM

Answers

  • User696746980 posted

    Create an Editor class inherited from AjaxControlToolkit.HTMLEditor.Editor and override the FillTopToolbar function:

    using System.Collections;
    using System.Collections.ObjectModel;
    namespace AjaxControlToolkit.HTMLEditor.Samples
    {
      public class NoFont: AjaxControlToolkit.HTMLEditor.Editor
      {
         protected override void FillTopToolbar()
         {
                TopToolbar.Buttons.Add(new ToolbarButton.Undo());
                TopToolbar.Buttons.Add(new ToolbarButton.Redo());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.Bold());
                TopToolbar.Buttons.Add(new ToolbarButton.Italic());
                TopToolbar.Buttons.Add(new ToolbarButton.Underline());
                TopToolbar.Buttons.Add(new ToolbarButton.StrikeThrough());
                TopToolbar.Buttons.Add(new ToolbarButton.SubScript());
                TopToolbar.Buttons.Add(new ToolbarButton.SuperScript());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.Ltr());
                TopToolbar.Buttons.Add(new ToolbarButton.Rtl());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
    
                ToolbarButton.FixedForeColor FixedForeColor = new ToolbarButton.FixedForeColor();
                TopToolbar.Buttons.Add(FixedForeColor);
                ToolbarButton.ForeColorSelector ForeColorSelector = new ToolbarButton.ForeColorSelector();
                ForeColorSelector.FixedColorButtonId = FixedForeColor.ID = "FixedForeColor";
                TopToolbar.Buttons.Add(ForeColorSelector);
                TopToolbar.Buttons.Add(new ToolbarButton.ForeColorClear());
    
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
    
                ToolbarButton.FixedBackColor FixedBackColor = new ToolbarButton.FixedBackColor();
                TopToolbar.Buttons.Add(FixedBackColor);
                ToolbarButton.BackColorSelector BackColorSelector = new ToolbarButton.BackColorSelector();
                BackColorSelector.FixedColorButtonId = FixedBackColor.ID = "FixedBackColor";
                TopToolbar.Buttons.Add(BackColorSelector);
                TopToolbar.Buttons.Add(new ToolbarButton.BackColorClear());
    
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.RemoveStyles());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
    
                TopToolbar.Buttons.Add(new ToolbarButton.Cut());
                TopToolbar.Buttons.Add(new ToolbarButton.Copy());
                TopToolbar.Buttons.Add(new ToolbarButton.Paste());
                TopToolbar.Buttons.Add(new ToolbarButton.PasteText());
                TopToolbar.Buttons.Add(new ToolbarButton.PasteWord());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.DecreaseIndent());
                TopToolbar.Buttons.Add(new ToolbarButton.IncreaseIndent());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.Paragraph());
                TopToolbar.Buttons.Add(new ToolbarButton.JustifyLeft());
                TopToolbar.Buttons.Add(new ToolbarButton.JustifyCenter());
                TopToolbar.Buttons.Add(new ToolbarButton.JustifyRight());
                TopToolbar.Buttons.Add(new ToolbarButton.JustifyFull());
                TopToolbar.Buttons.Add(new ToolbarButton.RemoveAlignment());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.OrderedList());
                TopToolbar.Buttons.Add(new ToolbarButton.BulletedList());
    
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.InsertHR());
                TopToolbar.Buttons.Add(new ToolbarButton.InsertLink());
                TopToolbar.Buttons.Add(new ToolbarButton.RemoveLink());
         }
      }
    


     

    If you want to redefine the default font family/size of Editor, use the DocumentCssPath property:

    <
    HTMLEditor:Editor runat="server" DocumentCssPath="myDocument.css" />

    myDocument.css file:

    body  {
     
    color:#404040; background-color: #fff;
     
    border-width: 0px; margin: 0px; padding: 2px;
      }

    body,table td
      {
     
    font-family: arial; font-size: 12pt;
      }

    h1  {
     
    font-size: 24pt;
      }

    h2  {
     
    font-size: 18pt;
      }

    h3  {
     
    font-size: 14pt;
      }

    h4  {
     
    font-size: 12pt;
      }

    h5  {
     
    font-size: 10pt;
       }

    h6  {
     
    font-size8pt;
      } 


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 1, 2009 8:13 PM

All replies

  • User696746980 posted

    Create an Editor class inherited from AjaxControlToolkit.HTMLEditor.Editor and override the FillTopToolbar function:

    using System.Collections;
    using System.Collections.ObjectModel;
    namespace AjaxControlToolkit.HTMLEditor.Samples
    {
      public class NoFont: AjaxControlToolkit.HTMLEditor.Editor
      {
         protected override void FillTopToolbar()
         {
                TopToolbar.Buttons.Add(new ToolbarButton.Undo());
                TopToolbar.Buttons.Add(new ToolbarButton.Redo());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.Bold());
                TopToolbar.Buttons.Add(new ToolbarButton.Italic());
                TopToolbar.Buttons.Add(new ToolbarButton.Underline());
                TopToolbar.Buttons.Add(new ToolbarButton.StrikeThrough());
                TopToolbar.Buttons.Add(new ToolbarButton.SubScript());
                TopToolbar.Buttons.Add(new ToolbarButton.SuperScript());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.Ltr());
                TopToolbar.Buttons.Add(new ToolbarButton.Rtl());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
    
                ToolbarButton.FixedForeColor FixedForeColor = new ToolbarButton.FixedForeColor();
                TopToolbar.Buttons.Add(FixedForeColor);
                ToolbarButton.ForeColorSelector ForeColorSelector = new ToolbarButton.ForeColorSelector();
                ForeColorSelector.FixedColorButtonId = FixedForeColor.ID = "FixedForeColor";
                TopToolbar.Buttons.Add(ForeColorSelector);
                TopToolbar.Buttons.Add(new ToolbarButton.ForeColorClear());
    
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
    
                ToolbarButton.FixedBackColor FixedBackColor = new ToolbarButton.FixedBackColor();
                TopToolbar.Buttons.Add(FixedBackColor);
                ToolbarButton.BackColorSelector BackColorSelector = new ToolbarButton.BackColorSelector();
                BackColorSelector.FixedColorButtonId = FixedBackColor.ID = "FixedBackColor";
                TopToolbar.Buttons.Add(BackColorSelector);
                TopToolbar.Buttons.Add(new ToolbarButton.BackColorClear());
    
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.RemoveStyles());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
    
                TopToolbar.Buttons.Add(new ToolbarButton.Cut());
                TopToolbar.Buttons.Add(new ToolbarButton.Copy());
                TopToolbar.Buttons.Add(new ToolbarButton.Paste());
                TopToolbar.Buttons.Add(new ToolbarButton.PasteText());
                TopToolbar.Buttons.Add(new ToolbarButton.PasteWord());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.DecreaseIndent());
                TopToolbar.Buttons.Add(new ToolbarButton.IncreaseIndent());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.Paragraph());
                TopToolbar.Buttons.Add(new ToolbarButton.JustifyLeft());
                TopToolbar.Buttons.Add(new ToolbarButton.JustifyCenter());
                TopToolbar.Buttons.Add(new ToolbarButton.JustifyRight());
                TopToolbar.Buttons.Add(new ToolbarButton.JustifyFull());
                TopToolbar.Buttons.Add(new ToolbarButton.RemoveAlignment());
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.OrderedList());
                TopToolbar.Buttons.Add(new ToolbarButton.BulletedList());
    
                TopToolbar.Buttons.Add(new ToolbarButton.HorizontalSeparator());
                TopToolbar.Buttons.Add(new ToolbarButton.InsertHR());
                TopToolbar.Buttons.Add(new ToolbarButton.InsertLink());
                TopToolbar.Buttons.Add(new ToolbarButton.RemoveLink());
         }
      }
    


     

    If you want to redefine the default font family/size of Editor, use the DocumentCssPath property:

    <
    HTMLEditor:Editor runat="server" DocumentCssPath="myDocument.css" />

    myDocument.css file:

    body  {
     
    color:#404040; background-color: #fff;
     
    border-width: 0px; margin: 0px; padding: 2px;
      }

    body,table td
      {
     
    font-family: arial; font-size: 12pt;
      }

    h1  {
     
    font-size: 24pt;
      }

    h2  {
     
    font-size: 18pt;
      }

    h3  {
     
    font-size: 14pt;
      }

    h4  {
     
    font-size: 12pt;
      }

    h5  {
     
    font-size: 10pt;
       }

    h6  {
     
    font-size8pt;
      } 


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 1, 2009 8:13 PM
  • User1658625817 posted

    I think that is going to work just perfect, thanks for the details and code.  I did however run into one strange [non-related] issue: 

    One thing I wanted to do differently was to put this new control in my own namespace.  So, I put this new class in my own namespace and then added a reference the AjaxControlToolkit.HTMLEditor with a 'using' statement at the top of the page.  However, this produces 'type could not be found' errors when I try to reference 'ToolbarButton'.  I can use the fully-qualified name 'AjaxControlToolkit.HTMLEditor.ToolbarButton.Undo()' and everything words fine.

    What is it that when I put this class under the AjaxControlToolkit.HTMLEditor namespace I can reference 'ToolbarButton' directly, but when I reference this namespace with 'using' I cannot?

    Thanks again.

     

    Wednesday, December 2, 2009 11:18 AM
  • User696746980 posted

    It's impossible...Frown
    Could you show the code? 

    Wednesday, December 2, 2009 8:02 PM
  • User1658625817 posted

    Sure, in the following code I get a squigley on the first 'ToolbarButton' portion of 'ToolbarButton.Undo()' with the error reading:

    The type or namespace 'ToolbarButton' could not be found (are you missing a.....

    using System.Collections;   
    using System.Collections.ObjectModel;
    using AjaxControlToolkit.HTMLEditor;
    
    namespace USMC.ServicePortal.MyControls
    {   
      public class LimitedEditor: AjaxControlToolkit.HTMLEditor.Editor   
      {   
        protected override void FillTopToolbar()   
        {
          TopToolbar.Buttons.Add(new ToolbarButton.Undo());  
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Redo());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HorizontalSeparator()); 
      
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Bold());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Italic());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Underline());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.StrikeThrough());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.SubScript());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.SuperScript());   
          
          //TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HorizontalSeparator());   
          //TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Ltr());   
          //TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Rtl());   
          
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HorizontalSeparator());   
          AjaxControlToolkit.HTMLEditor.ToolbarButton.FixedForeColor FixedForeColor = new AjaxControlToolkit.HTMLEditor.ToolbarButton.FixedForeColor();   
          TopToolbar.Buttons.Add(FixedForeColor);   
          AjaxControlToolkit.HTMLEditor.ToolbarButton.ForeColorSelector ForeColorSelector = new AjaxControlToolkit.HTMLEditor.ToolbarButton.ForeColorSelector();   
          ForeColorSelector.FixedColorButtonId = FixedForeColor.ID = "FixedForeColor";   
          TopToolbar.Buttons.Add(ForeColorSelector);   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.ForeColorClear());   
      
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HorizontalSeparator());   
          AjaxControlToolkit.HTMLEditor.ToolbarButton.FixedBackColor FixedBackColor = new AjaxControlToolkit.HTMLEditor.ToolbarButton.FixedBackColor();   
          TopToolbar.Buttons.Add(FixedBackColor);   
          AjaxControlToolkit.HTMLEditor.ToolbarButton.BackColorSelector BackColorSelector = new AjaxControlToolkit.HTMLEditor.ToolbarButton.BackColorSelector();   
          BackColorSelector.FixedColorButtonId = FixedBackColor.ID = "FixedBackColor";   
          TopToolbar.Buttons.Add(BackColorSelector);   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.BackColorClear());   
      
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HorizontalSeparator());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.RemoveStyles());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HorizontalSeparator());   
      
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Cut());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Copy());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Paste());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.PasteText());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.PasteWord());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HorizontalSeparator());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.DecreaseIndent());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.IncreaseIndent());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HorizontalSeparator());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Paragraph());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.JustifyLeft());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.JustifyCenter());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.JustifyRight());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.JustifyFull());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.RemoveAlignment());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HorizontalSeparator());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.OrderedList());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.BulletedList());   
      
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HorizontalSeparator());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.InsertHR());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.InsertLink());   
          TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.RemoveLink());   
        }   
      }  
    }
    
    


     

    Thursday, December 3, 2009 10:05 AM
  • User696746980 posted

    Hmm...
    I get the same result...

    Maybe it is incorrect  to start with a partial namespace: ToolbarButton.Undo() ?
    ToolbarButton is a namespace of AjaxControlToolkit.HTMLEditor.

    If you add the directive:

    using AjaxControlToolkit.HTMLEditor.ToolbarButton;


    You can use just:

          TopToolbar.Buttons.Add(new Undo());   


     

    Thursday, December 3, 2009 8:29 PM
  • User1658625817 posted

    Yeah I guess it's because ToolbarButton is a namespace and not a class, where as Undo() IS a class.  Thanks again for the help.

    Friday, December 4, 2009 8:56 AM