Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Switching culture(localization) with a single linkbutton

Posted on 2008-10-20
7
Medium Priority
?
446 Views
Last Modified: 2008-11-23
My issue is a client wants the switch of the culture to happen with a single link or linkbutton. It currently runs just fine and dandy with a dropdownlist. My issue I seem to be having is that I need a post back that reinilalizes the command arguement and text in the link button back to English even if I change the culture.
0
Comment
Question by:godirect
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 

Author Comment

by:godirect
ID: 22762554
Code attached of the basics.
<asp:LinkButton ID="LangDDL" OnClick="RequestLanguageChange_Click" Text="Español" CssClass="langMenu" CommandArgument="en-MX" runat="server"></asp:LinkButton>
 
Default.aspx.vb:
Protected Sub RequestLanguageChange_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If LangDDL.CommandArgument = "es-MX" Then
            SetCulture("es-MX", "es-MX")
            LangDDL.CommandArgument = "en-US"
            LangDDL.Text = "English"
        Else
            SetCulture("en-US", "en-US")
            LangDDL.CommandArgument = "es-MX"
            LangDDL.Text = "Espa&#241;ol"
        End If
    End Sub
 
BaseClass:
Protected Overrides Sub InitializeCulture()
        If Session("MyUICulture") IsNot Nothing AndAlso Session("MyCulture") IsNot Nothing Then
 
            Thread.CurrentThread.CurrentUICulture = DirectCast(Session("MyUICulture"), CultureInfo) 'New CultureInfo(Session("MyCulture"))
            Thread.CurrentThread.CurrentCulture = DirectCast(Session("MyCulture"), CultureInfo) 'CultureInfo.CreateSpecificCulture(Session("MyCulture"))
 
        End If
 
        MyBase.InitializeCulture()
    End Sub
 
 Public Sub SetCulture(ByVal name As String, ByVal locale As String)
 
        Thread.CurrentThread.CurrentUICulture = New CultureInfo(name)
        Thread.CurrentThread.CurrentCulture = New CultureInfo(locale)
        '///<remarks>
        '///Saving the current thread's culture set by the User in the Session
        '///so that it can be used across the pages in the current application.
        '///</remarks>
        Session("MyUICulture") = Thread.CurrentThread.CurrentUICulture
        Session("MyCulture") = Thread.CurrentThread.CurrentCulture
 
    End Sub

Open in new window

0
 
LVL 16

Expert Comment

by:ororiole
ID: 22762927
I dont understand the problem. Weren't you doing a postback with the dropdownlist as well? Were you doing async postbacks?
0
 

Author Comment

by:godirect
ID: 22766850
Yes I was doing a post back from a dropdownlist and it worked fine, but when I switched to a linkbutton I had to do a response.redirect to a refresh to get the new culture to take affect. When this in turn refreshed the link button to say Spanish again when the text on the page is turned to spanish.  I need to be able to change the page and swap back and forth between "English" and "Spanish" in the text of the link button.
0
 
LVL 16

Expert Comment

by:ororiole
ID: 22769888
Just to be clear, so everything is working ok EXCEPT the text on the linkbutton?

I will try this and get back to you.
0
 
LVL 16

Accepted Solution

by:
ororiole earned 2000 total points
ID: 22772272
I think the problem is you have an error in your linkbutton markup:
<asp:LinkButton ID="LangDDL" OnClick="RequestLanguageChange_Click" Text="Español" CssClass="langMenu" CommandArgument="en-MX" runat="server"></asp:LinkButton>
 
en-MX makes no sense so the else path is taken: culture IS set to esMX but the button remains "espanol". Change the markup to:
 
<asp:LinkButton ID="LangDDL" OnClick="RequestLanguageChange_Click" Text="Español" CssClass="langMenu" CommandArgument="es-MX" runat="server"></asp:LinkButton>

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question