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
Loading
v bPosted Jul 20, 2007, 4:50 PM
This is what I have so far...if anyone could comment I what they think or what they see may be wrong please do so:
Asp.net
<asp:DropDownList ID="LanguageDropDownList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="LanguageDropDownList_SelectedIndexChanged" OnPreRender="LanguageDropDownList_PreRender"> <asp:ListItem Value="en">Englishasp:ListItem> <asp:ListItem Value="de">Deutchasp:ListItem> asp:DropDownList>
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.SelectedValueResponse.Redirect(Page.AppRelativeVirtualPath,
True) ' No query string End SubGlobal.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(selectedLanguage)Thread.CurrentThread.CurrentCulture =
New CultureInfo(selectedLanguage) End If End If End Sub