it get the language from my config file and set the culture for the language it worked pefect when i used dropdownlist but now that i have changed the code to get the it from database i get the error:
String reference not set to an instance of a String
on line:
Dim ci As New System.Globalization.CultureInfo(language.Value)
it happens if the cookie is empty for the first time and it does not apply the Response.Redirect(Request.ServerVariables("SCRIPT_NAME")) here is my code
Protected Overloads Overrides Sub InitializeCulture()
' If config.Language IsNot Nothing Then ' Dim controlID As String = Request(PostBackEventTarget)
' If controlID.Equals(LanguageDropDownID) Then ' Dim selectedValue As String = Request.Form(Request(PostBackEventTarget)).ToString() Dim selectedValue As String = config.Language If Not selectedValue Is Nothing Then Select Case selectedValue Case "en" SetCulture("en-US", "en-US") Exit Select Case "de" SetCulture("de-DE", "de-DE") Exit Select Case "fr" SetCulture("fr-FR", "fr-FR") Exit Select Case "es" SetCulture("es-ES", "es-ES") Exit Select Case "it" SetCulture("it-IT", "it-IT") Exit Select Case "ar" SetCulture("ar-AR", "ar-AR") Exit Select Case "ir" SetCulture("fa-IR", "fa-IR") Exit Select Case "cn" SetCulture("cn-CN", "cn-CN") Exit Select Case "jp" SetCulture("jp-JP", "jp-JP") Exit Select Case "kr" SetCulture("kr-KR", "kr-KR") Exit Select Case "ru" SetCulture("ru-RU", "ru-RU") Exit Select Case Else ' SetCulture("en-US", "en-US") Exit Select End Select
End If
Dim language As HttpCookie = Request.Cookies("AutoLangCookie") Dim language2 As HttpCookie = Request.Cookies("AutoLangCookie2")
If language IsNot Nothing AndAlso language2 IsNot Nothing Then Dim ci As New System.Globalization.CultureInfo(language.Value) Dim ci2 As New System.Globalization.CultureInfo(language2.Value)
Thread.CurrentThread.CurrentUICulture = DirectCast(ci, CultureInfo) Thread.CurrentThread.CurrentCulture = DirectCast(ci2, CultureInfo) End If
MyBase.InitializeCulture()
'End If End Sub
Protected Sub SetCulture(ByVal name As String, ByVal locale As String) Thread.CurrentThread.CurrentUICulture = New CultureInfo(name) Thread.CurrentThread.CurrentCulture = New CultureInfo(locale)
Response.Cookies.Remove("AutoLangCookie") Response.Cookies("AutoLangCookie").Expires = DateTime.Now.AddDays(-1) Dim language As HttpCookie = New HttpCookie("AutoLangCookie") language.Value = Thread.CurrentThread.CurrentUICulture.ToString language.Expires = DateTime.MaxValue Response.Cookies.Add(language)
Response.Cookies.Remove("AutoLangCookie2") Response.Cookies("AutoLangCookie2").Expires = DateTime.Now.AddDays(-1) Dim language2 As HttpCookie = New HttpCookie("AutoLangCookie2") language2.Value = Thread.CurrentThread.CurrentCulture.ToString language2.Expires = DateTime.MaxValue Response.Cookies.Add(language2)
String reference not set to an instance of a String
According to the description above, it seems like that when language.Value is null. In order to resolve it, please check it at first and make sure it is not null before transfer. And check the similar thread:
keyvan1
Member
86 Points
272 Posts
change language dynamically problem:String reference not set to an instance of a String
Jan 22, 2013 02:51 PM|LINK
I have the following code in my basepage
it get the language from my config file and set the culture for the language it worked pefect when i used dropdownlist but now that i have changed the code to get the it from database i get the error:
String reference not set to an instance of a String
on line:
Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: change language dynamically problem:String reference not set to an instance of a String
Jan 25, 2013 07:34 AM|LINK
Hi,
According to the description above, it seems like that when language.Value is null. In order to resolve it, please check it at first and make sure it is not null before transfer. And check the similar thread:
http://forums.asp.net/t/1240035.aspx/1
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store