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

How to set default font name and font size from server side

7 Answers 735 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 23 May 2008, 02:07 PM
I know in the editor configuration file, we can set the default font name and font size for a rad editor control. But I want to set them from server side.

I have a page with a rad editor control. For the available fonts, I will get all the fonts available to the web server. Than I want to set the default font name and default font size to whatever a user has chosen and saved in our database.

For an editor object, I can finf properties such as DefultFontName or DefaultFontSize. How can I get that done?

Thanks.


Chris

7 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 23 May 2008, 03:28 PM
Hello Chris,

RadEditor does not offer the requested server DefultFontName and DefaultFontSize properties, but they are logged in our To-do list.

Here is how programmatically to apply the editor's content area and font appearance:

    protected void Page_Load(object sender, EventArgs e)
    {
        RadEditor1.OnClientLoad = "OnClientLoad";
        string js =
        @"<script type='text/javascript'>
        function OnClientLoad(editor, args)
        {
          var style = editor.get_contentArea().style;
          style.backgroundColor = 'black';
          style.color= 'red';
          style.fontFamily= 'Arial';
          style.fontSize= 15 + 'px';
        }
        </script>";
        Page.RegisterClientScriptBlock("myscriptkey", js); 
    }


Sincerely,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jeff Snyder
Top achievements
Rank 1
answered on 05 Jun 2008, 02:41 PM
I tried the suggestion in this thread, but I receive an error that RegisterClientScriptBlock is obsolete...  Can you update the suggestion?
0
Rumen
Telerik team
answered on 05 Jun 2008, 02:59 PM
Hи Jeff,

Here it is the requested updated example:

protected void Page_Load(object sender, EventArgs e)
{
    RadEditor1.OnClientLoad = "OnClientLoad";
    string js =
    @"<script type='text/javascript'>
    function OnClientLoad(editor, args)
    {
      var style = editor.get_contentArea().style;
      style.backgroundColor = 'black';
      style.color= 'red';
      style.fontFamily= 'Arial';
      style.fontSize= 15 + 'px';
    }
    </script>";
    ClientScript.RegisterClientScriptBlock(this.GetType(),"myscriptkey", js); 
}


Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
vitaly
Top achievements
Rank 1
answered on 24 Sep 2008, 02:53 PM
Hi,

i have default font size to 16px as sujested in above solution.  it does display that font indeed 16px in size, but when i try to get a Text from editor it does not contain formating for font size.  here's a sample.  both lines shown as size 16px in editor control,  first line i typed without changing font size, second line i have changed font size via drop down menu.  but when i get a value here's what i see.

"TEST<br />\r\n<span style=\"font-size: 16px\">TEST</span>\r\n"

please advice!

0
Rumen
Telerik team
answered on 29 Sep 2008, 10:12 AM
Hi Vitaly,

Have you tried the provided instructions in the following KB article:
No FONT tags are applied when I type text in the editor?


Another approach is to wrap the content on editor load inside a span tag with the desired default font. Here is an example:

<script type="text/javascript">
    function OnClientLoad(editor)
    {
            setTimeout(function()
            {
                editor.fire("FontSize", {value : "5"});
            }, 300);
   }
</script>
<telerik:radeditor OnClientLoad="OnClientLoad" runat="server" ID="RadEditor1"></telerik:radeditor>


Kind regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jeremy
Top achievements
Rank 1
answered on 08 May 2009, 03:51 AM
Hi Rumen,

Can you updated the link in you post. It's busted.

Cheers
0
Rumen
Telerik team
answered on 08 May 2009, 05:58 AM
Hi Jeremy,

Here is the new link: http://www.telerik.com/support/kb/aspnet-ajax/editor/no-font-tags-are-applied-when-i-type-text-in-the-editor.aspx

Sincerely,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Editor
Asked by
Chris
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Jeff Snyder
Top achievements
Rank 1
vitaly
Top achievements
Rank 1
Jeremy
Top achievements
Rank 1
Share this question
or