views:

84

answers:

2

Hi. I did Override InitializeCulture in base page.

Protected Overrides Sub InitializeCulture()
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("Fa-IR")
    Thread.CurrentThread.CurrentUICulture = New CultureInfo("Fa-IR")
    MyBase.InitializeCulture()
End Sub

but still my culture is english united state . and texts are english yet and are not persian.


I want to change it programmatically. I have local and global English and persian resources. i want to switch between them. How can i fix it?

when i put Protected Overrides Sub InitializeCulture() in main page it works great! but else when i put it in basepage not. what is the problem?

+1  A: 

If you want to set the culture for your entire ASP.NET site then you can do that in the web.config file:

<globalization uiCulture="Fa-IR" culture="Fa-IR" />

See Localization Made Easy article.

Dan Diplo
Thank you.But I want to change it programmatically.I have local and global English and persian resources.i want to switch between them.
shaahin
+1  A: 

I found it uncommon that you initialize the base class method with the last line. My first bet was, that this overrides your culture initialization. But I tested it - This isn’t the problem. Your code should work anyway.

Are you sure there is no other place with a culture initialization in your code? CurrentThread is a global variable and if you change it somewhere else (in a web control? in the data layer?) this will influence your page.

Here is my sample code, working for german/english. It should work for persian/english too.

Partial Public Class _Default
    Inherits BasePage
End Class

Public Class BasePage
    Inherits System.Web.UI.Page

    Protected Overrides Sub InitializeCulture()
        MyBase.InitializeCulture()
        Dim cultureInfo = New CultureInfo("de-DE")
        Thread.CurrentThread.CurrentCulture = cultureInfo
        Thread.CurrentThread.CurrentUICulture = cultureInfo
    End Sub
End Class
Dirk
thank you.when i put Protected Overrides Sub InitializeCulture()in main page it works great! but else when i put it in basepage not.what is the problem?
shaahin
If it works in one situation it should work in both situations. Stupid question: There is no empty InitializeCulture without base class initialization in main class if you test for base class?
Dirk
Dear Dirk.No :( .
shaahin
Last try. Put my working sample code into the answer. Good luck.
Dirk