classKey, resources and culture in ASP.NET

Last post 05-10-2005 2:14 PM by Luis Abreu. 6 replies.

Sort Posts:

  • Angry [:@] classKey, resources and culture in ASP.NET

    05-09-2005, 7:35 PM
    • Member
      20 point Member
    • DevInstinct
    • Member since 05-09-2005, 11:23 PM
    • Posts 4

    I've bound a button to a resource using the new expression using a classKey/ressource name pair:

    <asp:Button ID="Button1" runat="server" Text="<%$ Resources:ResourceWeb,MyResource %>" />

    I've created 2 resource files for this. ResourceWeb.resx and ResourceWeb.fr.resx

    When I change the culture using:

    Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr");

    The button still shows the text in the default resource and doesn't switch to fr

    How can we change the culture of our page dynamically when using the classKey as an alternative to the resource manager?

    -- Using VS 2005 Beta 2

  • Re: classKey, resources and culture in ASP.NET

    05-10-2005, 12:43 AM
    • Contributor
      6,299 point Contributor
    • BrockAllen
    • Member since 05-05-2003, 2:46 PM
    • Providence, RI
    • Posts 1,255

    When do you change the Thread's UICulture? This needs to be done before the page is executed, so somewhere in global.asax such as PreRequestHandlerExeute.

    -Brock

     

    DevelopMentor
    http://staff.develop.com/ballen
  • Re: classKey, resources and culture in ASP.NET

    05-10-2005, 4:15 AM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 1:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs

    Hello.

    As an alternative to what Brock said I think that you can also override the InitilizeCulture method of the Page class and do your initialization there.

    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: classKey, resources and culture in ASP.NET

    05-10-2005, 9:07 AM
    • Member
      20 point Member
    • DevInstinct
    • Member since 05-09-2005, 11:23 PM
    • Posts 4

    I was doing it in BeginRequest and tried it in PreRequestHandlerExecute (which doesn't work).

    The right solution is to use InitializeCulture.

    Thanks!

  • Re: classKey, resources and culture in ASP.NET

    05-10-2005, 10:10 AM
    • Contributor
      6,299 point Contributor
    • BrockAllen
    • Member since 05-05-2003, 2:46 PM
    • Providence, RI
    • Posts 1,255
     DevInstinct wrote:

    I was doing it in BeginRequest and tried it in PreRequestHandlerExecute (which doesn't work).

    This works for me. Why is this not working for you?

     DevInstinct wrote:

    The right solution is to use InitializeCulture

    It depends. This gets back to a similar debate that we were having over on another thread about how to initalize themes application wide. The InitalizeCulture approach requires this to be done in every page (or in a common base class) which I find to be an unappealing approach. I prefer the PreRequestHandlerExecute approach to be better, as it's application wide and outside of the page.

    -Brock

     

    DevelopMentor
    http://staff.develop.com/ballen
  • Re: classKey, resources and culture in ASP.NET

    05-10-2005, 10:52 AM
    • Member
      20 point Member
    • DevInstinct
    • Member since 05-09-2005, 11:23 PM
    • Posts 4
     BrockAllen wrote:

    This works for me. Why is this not working for you?

    I searched and found out why (we're like that aren't we? Can't simply continue working until we know the WHYS and HOWSWink [;)]).

    If you've got a UI culture specified in design view thru properties, global.asax doesn't override it, but InitializeCulture does.

    I agree with you that a generic approach is better, so I'd recommand not to use the design properties for culture.

    Thanks again!

     

  • Re: classKey, resources and culture in ASP.NET

    05-10-2005, 2:14 PM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 1:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs
    Despite having suggestes InitializeCulture, I'm forced to agree with Brock's opinion on this.
    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
Page 1 of 1 (7 items)