I'm able to change the language for my pages, however if I select french and I am on a current page and if I try to load another page, that page won't be in french. How can I set it so it is consistent throught?
Toggle Button in master page:
If Page.Culture = "English (United States)" Then Response.Redirect(Request.Url.AbsolutePath + "?lang=fr-CA") ElseIf Page.Culture = "French (Canada)" Then Response.Redirect(Request.Url.AbsolutePath + "?lang=en-US") End Ifand in every page:
Protected Overrides Sub InitializeCulture() Dim lang As String = String.Empty
lang = Request.QueryString("lang")
If lang IsNot Nothing Then
Session("culture") = lang
Thread.CurrentThread.CurrentCulture = New CultureInfo(lang)
Thread.CurrentThr开发者_开发知识库ead.CurrentUICulture = New CultureInfo(lang)
Else
If Session("culture") IsNot Nothing Then
lang = Session("culture").ToString()
Thread.CurrentThread.CurrentCulture = New CultureInfo(lang)
Thread.CurrentThread.CurrentUICulture = New CultureInfo(lang)
End If
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-US")
End If
MyBase.InitializeCulture()
End Sub
I suppose the querystring parameters are not posted back when changing from page as aposed to toggling in the master page.
Can you try and debug the application to see what your Request.QueryString collection is when changing from page?
Maybe a better way to store the culture would be in a cookie or (if your using asp.net membership) in the users profile.
May I also note that a base page would be handy to implement the InitializeCulture method instead of repeating it in every page if that's the case.
精彩评论