Knowledge Base > RichTextBox > Features Knowledge Base Home | Login
Search the Knowledge Base
 
Start Search in the Following Category

Multiple cultures on one page

Although RichTextBox v3.0 does not support multiple editors on the same page having different culture settings, we have due to demand, created an unsupported solution that allows this.

 

Please note that this is an unsupported interim solution which has undergone very little testing, and might therefore prove unstable in different circumstances.

 

The solution requires that you subclass the editor. You then need to override the OnPreRender method in which you temporarily change the culture of the executing thread, call RichTextBox’s (base) OnPreRender method, and change the culture back to its original state. That’s about it.

 

Note: you must ensure that the appropriate resource folders - for example en-GB, are in the bin directory of your Web Application. These are located at \Program Files\RichTextBox v3.0\Bin\

 

The below example uses the SRC attribute on Page directive to include the classes, but you are free to compile these classes and reference the DLL(s) in the aspx page instead (example further below). There most certainly are other ways to achieve the same functionality, so please let us know if you need additional assistance, or have any comments.

 

 

The sample class page:

 

using RichTextBoxControl;

using System.Web;

using System.Web.UI;

using System.Threading;

using System;

using System.Globalization;

 

public class RTBFrench : RichTextBox {

        protected override void OnPreRender(EventArgs e) {

                CultureInfo c=Thread.CurrentThread.CurrentUICulture;

                Thread.CurrentThread.CurrentUICulture=CultureInfo.CreateSpecificCulture("FR");

 

                base.OnPreRender(e);

 

                Thread.CurrentThread.CurrentUICulture=c;

        }

}

public class RTBEnglish : RichTextBox {

        protected override void OnPreRender(EventArgs e) {

                CultureInfo c=Thread.CurrentThread.CurrentUICulture;

                Thread.CurrentThread.CurrentUICulture=CultureInfo.CreateSpecificCulture("EN");

 

                base.OnPreRender(e);

 

                Thread.CurrentThread.CurrentUICulture=c;

        }

}

 

The sample .aspx page:

 

<%@ Page Language="C#" src="MultiLang.cs" %>

<%@ Register TagPrefix="RTB" Namespace="RichTextBoxControl" Assembly="RichTextBox" %>

<HTML>

        <HEAD>

                <script runat="server">

 

    private void Page_Load(object sender, System.EventArgs e)

    {

        RichTextBox french=new RTBFrench();

        RichTextBox english=new RTBEnglish();

 

        french.ID="french";

        english.ID="english";

 

 

        rtbFrench.Controls.Add(french);

        rtbEnglish.Controls.Add(english);

    }

 

                </script>

        </HEAD>

        <body>

                <form runat="server">

 

                        <div runat="server" id="rtbFrench"></div>

                        <div runat="server" id="rtbEnglish"></div>

                </form>

        </body>

</HTML>

 

Compiled .dll solution -

 

Class MultiLang.cs -

 

using RichTextBoxControl;

using System.Web;

using System.Web.UI;

using System.Threading;

using System;

using System.Globalization;

 

namespace MultiLang

{

        public class RTBFrench : RichTextBox

        {

 

                protected override void OnPreRender(EventArgs e)

                {

 

                        CultureInfo c=Thread.CurrentThread.CurrentUICulture;

                        Thread.CurrentThread.CurrentUICulture=CultureInfo.CreateSpecificCulture("FR");

 

                        base.OnPreRender(e);

 

                        Thread.CurrentThread.CurrentUICulture=c;

 

                }

 

        }

 

        public class RTBEnglish : RichTextBox

        {

 

                protected override void OnPreRender(EventArgs e)

                {

                        CultureInfo c=Thread.CurrentThread.CurrentUICulture;

                        Thread.CurrentThread.CurrentUICulture=CultureInfo.CreateSpecificCulture("EN");

 

                        base.OnPreRender(e);

 

                        Thread.CurrentThread.CurrentUICulture=c;

 

                }

 

        }

 

}

 

.aspx page -

 

<%@ Page Language="C#"%>

 

<HTML>

   <HEAD>

    <script runat="server">

 

    private void Page_Load(object sender, System.EventArgs e)

 

    {

            RichTextBoxControl.RichTextBox french = new MultiLang.RTBFrench();

            RichTextBoxControl.RichTextBox english = new MultiLang.RTBEnglish();

           

            french.ID="french";

            english.ID="english";

           

            divFrench.Controls.Add(french);

            divEnglish.Controls.Add(english);

 

    }

 

    </script>

   </HEAD>

            <body>

                        <form runat="server" ID="Form1">

 

                                    <div runat="server" id="divFrench"></div>

                                    <div runat="server" id="divEnglish"></div>

 

                        </form>

 

            </body>

 

</HTML>

  




Did this page answer your question? If not, try the Forums or contact us.

Copyright Richer Components 2005. All rights reserved. No part of this article may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording or otherwise) without the prior written permission of Richer Components. All brand names and product names used in this article are trade names, service marks, trademarks, or registered trademarks of their respective owners.


Knowledge Base Software - myKB.com