This is a migrated thread and some comments may be shown as answers.

ApplyClass droplist not populating with cssFiles classes

2 Answers 63 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 03 Nov 2011, 09:43 PM
I have an existing rad editor in a webpage that loads an HTML document with css markup.  The document contains links to external css files, and both the document and its css files are in a completely different place than that of the folder in which the editor webpage resides.  I programatically add the css files to the editor through the codebehind.

When I run the editor, the document loads and renders with the correct css markup in design mode.  When I move the editor's cursor over the content area, the ApplyClass toolbar button displays the correct name of any class that happens to be under the cursor's position.  But, when I expand the ApplyClass droplist, I find that it is empty with the exception of a single entry "Clear Class".  The droplist does not contain any of the classes in the css files I've programatically added to the cssfiles property.

My understanding is that if the cssclasses property is set to be empty, the editor should automatically load all the class names contained in the files specified by cssfiles.  I've done this too, but it didn't help.  Do you know what's going wrong?  I don't want to hardcode any class names as the css files are dynamically generated and will always be changing for each editing session.

I'm using Telerik RAD controls 2011.2.915.35 on windows 7 SP1 and am launching the page from inside of visual studio 2008 on the personal web browser.

The code in which I take a directory of the document folder and add all the css files found follows:

protected System.String loadCSS(System.String strFilePath,  ref RadEditor radEditor)
{
    System.String result = "OK";
    try
    {
        if (strFilePath.IndexOf(":") < 0 && strFilePath.IndexOf("//") < 0)
        {
            strFilePath = Server.MapPath(strFilePath);//its a virtual path so map it to a physical one
        }

        System.String strPublishingFolder = Path.GetDirectoryName(strFilePath);
        foreach (System.String strCSSfile in Directory.GetFiles(strPublishingFolder, "*.css"))
        {
            radEditor.CssFiles.Add(strCSSfile);
        }//EOF strCSSfile in Directory.GetFiles
        radEditor.CssClasses.Add("", "");
    }
    catch (Exception ex)
    {
        System.Object oe = (Object)ex;
        result = "loadCSS: " + et.rptError(ref oe);
    }//try
    return result;
}//EOF loadCSS


The rad editor control markup is:

<telerik:RadEditor ID="telerikeditor" Runat="server" 
                   OnClientLoad="onClientLoad"
                   OnClientCommandExecuting="OnClientCommandExecuting">
    <Tools>
        <telerik:EditorToolGroup Tag="grpInputOutput">
            <telerik:EditorTool ImageUrl="Images/radeditorSave.gif" 
                Name="Save" ShowText="False" 
                Text="Save" />
            <telerik:EditorTool ImageUrl="Images/radeditorSaveAs.gif" 
                Name="SaveAs" ShowText="False" 
                Text="Save As" />
            <telerik:EditorSeparator />    
            <telerik:EditorTool Name="PageProperties" />
            <telerik:EditorTool Name="Print" />  
        </telerik:EditorToolGroup>    
        <telerik:EditorToolGroup Tag="grpAids"
            <telerik:EditorTool Name="Help" />
            <telerik:EditorDropDown Name="Zoom"></telerik:EditorDropDown>
        </telerik:EditorToolGroup>
        <telerik:EditorToolGroup Tag="grpCheckers">
             <telerik:EditorTool Name="AjaxSpellCheck" />
         </telerik:EditorToolGroup>
         <telerik:EditorToolGroup Tag="grpFind">
             <telerik:EditorTool Name="FindAndReplace" />
             <telerik:EditorTool Name="SelectAll" />
         </telerik:EditorToolGroup>
         <telerik:EditorToolGroup Tag="grpRecover">
          <telerik:EditorSplitButton Name="Undo"></telerik:EditorSplitButton>
          <telerik:EditorSplitButton Name="Redo"></telerik:EditorSplitButton>
         </telerik:EditorToolGroup>
         <telerik:EditorToolGroup Tag="grpCutNpaste">
           <telerik:EditorTool Name="Cut" />
           <telerik:EditorTool Name="Copy" />
           <telerik:EditorTool Name="Paste" ShortCut="CTRL+V" />
           <telerik:EditorSeparator />
           <telerik:EditorTool Name="PasteFromWord" />
           <telerik:EditorTool Name="StripWord" />
         </telerik:EditorToolGroup>
         <telerik:EditorToolGroup Tag="grpInsert">
            <telerik:EditorTool Name="InsertParagraph" />
            <telerik:EditorSplitButton Name="InsertSymbol"></telerik:EditorSplitButton>
         </telerik:EditorToolGroup>
         <telerik:EditorToolGroup Tag="grpTextFont">
             <telerik:EditorDropDown Name="FormatBlock"></telerik:EditorDropDown>
             <telerik:EditorDropDown Name="FontName"></telerik:EditorDropDown>
             <telerik:EditorDropDown Name="RealFontSize"></telerik:EditorDropDown>
         </telerik:EditorToolGroup>
         <telerik:EditorToolGroup Tag="grpMarkup">
              <telerik:EditorTool Name="ApplyClass"></telerik:EditorTool>
              <telerik:EditorTool Name="Bold" />
              <telerik:EditorTool Name="Italic" />
              <telerik:EditorTool Name="Underline" />
              <telerik:EditorTool Name="ConvertToLower" />
              <telerik:EditorTool Name="ConvertToUpper" />
               <telerik:EditorTool Name="InsertHorizontalRule" />
          </telerik:EditorToolGroup>
          <telerik:EditorToolGroup Tag="grpAlignment">
              <telerik:EditorTool Name="JustifyLeft" />
              <telerik:EditorTool Name="JustifyCenter" />
              <telerik:EditorTool Name="JustifyRight" />
              <telerik:EditorTool Name="JustifyFull" />
          </telerik:EditorToolGroup>
          <telerik:EditorToolGroup Tag="grpLists">
              <telerik:EditorTool Name="InsertOrderedList" />
              <telerik:EditorTool Name="InsertUnorderedList" />
              <telerik:EditorSeparator />
              <telerik:EditorTool Name="Indent" />
              <telerik:EditorTool Name="Outdent" />
          </telerik:EditorToolGroup>
            <telerik:EditorToolGroup Tag="grpImages">
                <telerik:EditorTool Name="InsertImage" />
                <telerik:EditorTool Name="ImageManager" ShortCut="CTRL+M" />
            </telerik:EditorToolGroup>
            <telerik:EditorToolGroup Tag="grpCalendar">
                <telerik:EditorTool Name="InsertDate" />
                <telerik:EditorTool Name="InsertTime" />                
            </telerik:EditorToolGroup>
     </Tools>
     <Content>
     </Content>
</telerik:RadEditor>

2 Answers, 1 is accepted

Sort by
0
Andy
Top achievements
Rank 1
answered on 07 Nov 2011, 08:22 PM
Found the problem...the rad editor is designed to use virtual file paths, not physical ones as these eventually get inserted into the HTML page. 
0
Rumen
Telerik team
answered on 08 Nov 2011, 01:29 PM
Hi Andy,

I am glad that you fixed the problem.

I just want to add that the radEditor.CssClasses.Add("", ""); will clear all the style items in the Apply Class dropdown. More information about the CssClasses property is available in the following help article: Css Styles.

Greetings,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Editor
Asked by
Andy
Top achievements
Rank 1
Answers by
Andy
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or