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

Set content text color in code behind

3 Answers 256 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 02 Aug 2011, 02:30 PM
Hi,

Here is our scenario. We have a screen where users need to add their comment in a text editor. What we would like to achieve is that the color is fixed based on the user role.
We have tried the following code but without any luck:

RadEditor tbOpmerkingen = editedItem.FindControl("tbOpmerkingen") as RadEditor;
            tbOpmerkingen.ForeColor = System.Drawing.Color.Blue;

and 

tbOpmerkingen.ContentAreaCssFile = "~/App_Themes/easecc/Test.css";

css looks like
.RadEContent
{
color: Blue !important;
}

and 

Literal styleSheet = (Literal)this.Master.FindControl("styleSheet");
 styleSheet.Text = ".RadEContent{color: Blue !important;}";

with in the masterpage header section

    <style>
       <asp:Literal id="styleSheet" runat="server"></asp:Literal>
   </style>

Any help on this issue is appreciated.
Ron

3 Answers, 1 is accepted

Sort by
0
Gimmik
Top achievements
Rank 1
answered on 02 Aug 2011, 05:05 PM
Hi Ron,

I think I found a way to do this, but it takes a few steps.

First, you'll have to create a custom CSS file for each user level and save them into a folder in your web app. Here is the sample I created
MyCSS.css :
body
{
    color: Blue !important;
}

Now, you can programmatically set the ContentAreaCssFile property for RadEditor to whatever CSS file you've assigned that that particular user group. Here is my code-behind. You'll be replacing [ if (true) ] with your conditional user logic.

C#:
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
 
        if (true)
        {
            RadEditor1.ContentAreaCssFile = "~/CSS/MyCSS.css";
        }
 
 
        RadEditor1.EnsureToolsFileLoaded();
        RemoveButton("ForeColor");
 
        RadEditor1.StripFormattingOptions = EditorStripFormattingOptions.Css;
 
    }
 
}
 
public void RemoveButton(string name)
{
    foreach (Telerik.Web.UI.EditorToolGroup group in RadEditor1.Tools)
    {
        EditorTool tool = group.FindTool(name);
        if (tool != null)
        {
            group.Tools.Remove(tool);
        }
    }
}

The other item you might notice about the code above is the RemoveButton logic. This is to prevent the user from changing the forecolor of the text by removing the ForeColor button from the RadEditor.

Finally, the StripFormattingOptions section will ensure that a "Blue Level" user can not copy/paste Red text into the RadEditor.

Let me know if that works for you.

-Gimmik
0
Ron
Top achievements
Rank 1
answered on 03 Aug 2011, 10:12 AM
Hi Gimmik,

Yup your solution does work. However It turns all text within the editor to the color from the body setting.

I would like to control the color the user is typing in f.e.
all the text  typed in by rolea should be green
all the text typed in by role b should be blue

So when both roles a their comment to the same record you should see  a  mixture of green and blue text.
Sorry if my previous question was not clear enough.
Ron
0
Gimmik
Top achievements
Rank 1
answered on 17 Aug 2011, 05:50 PM
Hi Ron,

I looked into this issue some more and I'm not sure that it's possible to do what you want to do with the RadEditor. It seems to be a limitation of the Rich Text technology that the RadEditor is built upon. A Document Model environment such as Microsoft Word can handle such situations much better. The particular feature I couldn't get working was in-line editing. For example, If you types "The fox jumps over the fence" and the text appears in blue, then I update it to read "The BROWN fox jumps over the fence" - I assume you would want the word brown to be a different color. I don't currently see a way to do this type of inline editing.
Tags
Editor
Asked by
Ron
Top achievements
Rank 1
Answers by
Gimmik
Top achievements
Rank 1
Ron
Top achievements
Rank 1
Share this question
or