0

i have a button when i click it, it should switch the language or culture of the application, the problem is that i alawys get null referece exception for the button here is my vb code

 Protected Overrides Sub InitializeCulture()

    If ddlLanguages2.InnerText.ToString.Trim.Equals(("English").ToString.Trim) Then
        ddlLanguages2.InnerText = "عربي"
        Dim selectedLanguage As String = "en-us"
        UICulture = "en-us"
        Culture = "en-us"
        Thread.CurrentThread.CurrentCulture =
            CultureInfo.CreateSpecificCulture(selectedLanguage)
        Thread.CurrentThread.CurrentUICulture = New _
            CultureInfo(selectedLanguage)

    ElseIf ddlLanguages2.InnerText.ToString.Trim.Equals(("عربي").ToString.Trim) Then
        ddlLanguages2.InnerText = "English"
        Dim selectedLanguage As String =
           "ar-kw"
        UICulture = "ar-kw"
        Culture = "ar-kw"
        Thread.CurrentThread.CurrentCulture =
            CultureInfo.CreateSpecificCulture(selectedLanguage)
        Thread.CurrentThread.CurrentUICulture = New _
            CultureInfo(selectedLanguage)

    End If
    MyBase.InitializeCulture()
End Sub



Protected Sub ddlLanguages_SelectedIndexChanged(sender As Object, e As EventArgs)

    InitializeCulture()

End Sub

it stops when it reaches the the first "if" statement,by the way, any control does't work within the InitializeCulture

  <button id="ddlLanguages2" style="margin-top: 5px" runat="server" 
  onserverclick="ddlLanguages_SelectedIndexChanged">
                                    عربي
                        </button>

any help would be appreciated

  • Enable CLR Exceptions, you will get he exact line where the code is breaking. Or post the stack trace. It will help – PSK Feb 05 '18 at 07:06
  • i know where it breaks , in the first if statement If ddlLanguages2.InnerText.ToString.Trim.Equals(("English").ToString.Trim) Then – ahmed jallad Feb 05 '18 at 07:21
  • check if the item exists in the list like ddlLanguages2.Items.FindByText – PSK Feb 05 '18 at 07:23
  • i dont have a list, i just forgot to change the name to proper one – ahmed jallad Feb 05 '18 at 07:32
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – VDWWD Feb 05 '18 at 09:38

0 Answers0