chibear1986
New member
Summary: Basically I've localized my application and am trying to add in a asp style drop down list which has different languages to choose from, and on selection(postback) will change the pages language to whatever was selected. I'm trying to insert this drop down list into the header of my app. which has a compenentart style menu.
Problem: When I start doing the actual coding to make this function work i run into a problem. If my app. didn't have the compenentart user control I would just put in the following code:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Overrides Sub InitializeCulture()
Dim lang As String = Request("DropDownList1")
If lang IsNot Nothing Or lang <> "" Then
Thread.CurrentThread.CurrentUICulture = New CultureInfo(lang)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang)
End If
End Sub
The problem is that since the page has user controls I obviously can use the " Inherits System.Web.UI.Page". B/C if i do change it to this and leave the rest of the code the same the app throws an error...it states, "sub 'InitializeCulture' cannot be declared 'Overrides' because it does not override a sub in a base class
Any thoughts, suggestions? I willing to go about this another way if possible...thanks in advanced
-----------------------------------------
I've been attempting to figure it out all day and have made progress but still can't figure it out...
This is what I have added so far...if anyone could comment I what they think or what they see may be wrong please do so:
Asp.net
<asp
ropDownList ID="LanguageDropDownList" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="LanguageDropDownList_SelectedIndexChanged"
OnPreRender="LanguageDropDownList_PreRender">
<asp:ListItem Value="en">English</asp:ListItem>
<asp:ListItem Value="de">Deutch</asp:
</asp
ropDownList>
Vb Code:
Protected Sub LanguageDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles LanguageDropDownList.SelectedIndexChanged
Dim ddl As DropDownList = CType(sender, DropDownList)
' TODO: Validate that ddl.SelectedValue is valid TwoLetterISOLanguageName
Session("SelectedLanguage") = ddl.SelectedValue
Response.Redirect(Page.AppRelativeVirtualPath, True)
' No query string
End Sub
Global.ascx
Private Sub Application_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
If Not (Context.Session Is Nothing) AndAlso Not (Context.Session("SelectedLanguage") Is Nothing) Then
Dim selectedLanguage As String = Context.Session("SelectedLanguage").ToString.ToLower
Dim currentLanguage As String = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.ToLower
If Not currentLanguage.Equals(selectedLanguage) Then
Thread.CurrentThread.CurrentUICulture = New CultureInfo(selectedLa
Problem: When I start doing the actual coding to make this function work i run into a problem. If my app. didn't have the compenentart user control I would just put in the following code:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Overrides Sub InitializeCulture()
Dim lang As String = Request("DropDownList1")
If lang IsNot Nothing Or lang <> "" Then
Thread.CurrentThread.CurrentUICulture = New CultureInfo(lang)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang)
End If
End Sub
The problem is that since the page has user controls I obviously can use the " Inherits System.Web.UI.Page". B/C if i do change it to this and leave the rest of the code the same the app throws an error...it states, "sub 'InitializeCulture' cannot be declared 'Overrides' because it does not override a sub in a base class
Any thoughts, suggestions? I willing to go about this another way if possible...thanks in advanced
-----------------------------------------
I've been attempting to figure it out all day and have made progress but still can't figure it out...
This is what I have added so far...if anyone could comment I what they think or what they see may be wrong please do so:
Asp.net
<asp

OnSelectedIndexChanged="LanguageDropDownList_SelectedIndexChanged"
OnPreRender="LanguageDropDownList_PreRender">
<asp:ListItem Value="en">English</asp:ListItem>
<asp:ListItem Value="de">Deutch</asp:
</asp

Vb Code:
Protected Sub LanguageDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles LanguageDropDownList.SelectedIndexChanged
Dim ddl As DropDownList = CType(sender, DropDownList)
' TODO: Validate that ddl.SelectedValue is valid TwoLetterISOLanguageName
Session("SelectedLanguage") = ddl.SelectedValue
Response.Redirect(Page.AppRelativeVirtualPath, True)
' No query string
End Sub
Global.ascx
Private Sub Application_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
If Not (Context.Session Is Nothing) AndAlso Not (Context.Session("SelectedLanguage") Is Nothing) Then
Dim selectedLanguage As String = Context.Session("SelectedLanguage").ToString.ToLower
Dim currentLanguage As String = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.ToLower
If Not currentLanguage.Equals(selectedLanguage) Then
Thread.CurrentThread.CurrentUICulture = New CultureInfo(selectedLa