Custom Control Setting the Page.UICulture

Rate It (1)

Last post 09-27-2007 12:06 PM by MADCookie. 2 replies.

Sort Posts:

  • Custom Control Setting the Page.UICulture

    09-26-2007, 7:40 PM
    • Loading...
    • MADCookie
    • Joined on 02-20-2003, 4:43 AM
    • Posts 7

    I write composite controls (System.Web.UI.WebControls.CompositeControl).

    Is it possible to create a composite control that sets the page's Culture and UICulture? I have seen many examples where a page changes its own culture by overriding the page's InitializeCulture(). What I need to do now is deliver a control library DLL so the client can add a new "Culture Selector" control. How would you all do this?
     

     

  • Re: Custom Control Setting the Page.UICulture

    09-27-2007, 5:41 AM
    • Loading...
    • vivek_iit
    • Joined on 06-18-2006, 2:13 PM
    • New Delhi
    • Posts 3,077
    • TrustedFriends-MVPs

     InitializeCulture fires very early in the page lifecycle method, a time when no controls are initialized. AFAIK you cannot override that method in a  custom control/user control. what you can do is to set some variable when your custom control event fires, and capture that during page classes initializeculture method.

    hope this helps,

    Vivek 

    MVP, ASP.NET || My Website || Blog || Articles

    Please mark the most helpful reply/replies as "Answer".
  • Re: Custom Control Setting the Page.UICulture

    09-27-2007, 12:06 PM
    • Loading...
    • MADCookie
    • Joined on 02-20-2003, 4:43 AM
    • Posts 7

    vivek_iit:

    InitializeCulture fires very early in the page lifecycle method, a time when no controls are initialized. AFAIK you cannot override that method in a  custom control/user control.

     

     

    I agree a control cannot override that specific event. I believe that new method was made available to make it easy for culture programming. What I'm really searching for is a way that a custom control can fire up the behavior.

    I have this code in my control, which is the same code used in the InitializeCulture method. Why does it no longer effect the thread or page?  

     

    Dim selectedLanguage As String = radSelector.SelectedValue
    
    Page.Culture = selectedLanguage
    Page.UICulture = selectedLanguage
    
    System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage)
    System.Threading.Thread.CurrentThread.CurrentUICulture = New CultureInfo(selectedLanguage)
      
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter