I have a multilingual company website (Visual Studio / VB / ASP.NET 4.0), and when, on the homepage, you click a flag, the text changes to that language and stays with you the entire session, after I made a class, BasePage.vb. Everything works great, but the URL never changes …. clients.aspx remains clients.aspx although the text DOES switch to Dutch.
It’s been recommended by @Aritstos to make it so it looks like clients.aspx?lang=nl as opposed to just clients.aspx in another language.
Currently, my asp homepage hyperlinks that work look like this:
<asp:LinkButton ID="LinkButton7" runat="server"
CommandArgument="nl" OnClick="RequestLanguageChange_Click"
class="flagbutton">
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/flagnl.png"
tooltip="Bekijk deze website in het Nederlands" title="Bekijk deze website
in het Nederlands"/>
<img class="map" src="images/flaghovernl.png" alt=""/>
</asp:LinkButton>
I tried to change the asp links to html links, like this:
<a href="default.aspx?lang-nl" class="flagbutton">
<img src="images/flagnl.png" alt="Bekijk deze website in het Nederlands"
title="Bekijk deze website in het Nederlands"/>
<img class="map" src="images/flaghovernl.png" alt=""/>
But that didn’t work. The page doesn’t switch languages to Dutch. And when I click on any link, say, about.aspx, the ?lang-nl disappears. So nothing appears in Dutch. I was told the asplinks do the javascript_dopostback? which is bad. Can somebody please tell me how to change my links so that they create a string at the end of the URL saying “?lang-nl” at the end, and it stays like that through their entire session? Any help would be sincerely appreciated!
PS — here is the code for my BasePage.vb:
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Globalization
Imports System.Threading
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Namespace Udev.MasterPageWithLocalization.Classes
''' <summary>
''' Custom base page used for all web forms.
''' </summary>
Public Class BasePage
Inherits Page
Protected Overrides Sub InitializeCulture()
'retrieve culture information from session
Dim culture__1 As String =
Convert.ToString(Session([Global].SESSION_KEY_CULTURE))
'check whether a culture is stored in the session
If culture__1.Length > 0 Then
Culture = culture__1
End If
'set culture to current thread
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(culture__1)
Thread.CurrentThread.CurrentUICulture = New CultureInfo(culture__1)
'call base class
MyBase.InitializeCulture()
End Sub
End Class
End Namespace
In my Global.vb, I have this:
Namespace Udev.MasterPageWithLocalization.Classes
''' <summary>
''' Summary description for Global
''' </summary>
Public Structure [Global]
Public Const SESSION_KEY_CULTURE As String = "culture"
End Structure
End Namespace
In my Culture.vb, I have this:
Namespace Udev.MasterPageWithLocalization.Classes
''' <summary>
''' This class provides ISO definitions for all cultures that are supported by
this application.
''' </summary>
Public Structure Culture
'German - Switzerland definition
Public Const DE As String = "de"
'English - Great Britain definition
Public Const EN As String = "en"
End Structure
End Namespace
to read parameters from the url in your case is the (lang) in clients.aspx?lang=nl you can use:
this way you can use a simple if or a select case statements to determine which language the user is requesting. something like this:
now to keep the same language to the user as she navigates the site you can save it in a session using the code:
and to read the session value use the code:
now when we combine both methods and making sure there will be no conflic: