locked
ImageButton Localization for LanguageChange RRS feed

  • Question

  • User144738434 posted

    Friends of Asp.net!

     

    I have a Language solution going. 2 languages.

    My setup is like this;

    MasterPage

     

    <asp:ImageButton ID="ImageButton1" runat="server" CssClass="no" onclick="EnglishButton_Click"/> 

     

    Masterpage.vb

     

    Inherits System.Web.UI.MasterPage

     

    Protected Sub EnglishButton_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)

            Dim selectedLanguage As String = "en"

            'Sets the cookie that is to be used by InitializeCulture() in content page

            Dim cookie As New HttpCookie("CultureInfo")

            cookie.Value = selectedLanguage

            Response.SetCookie(cookie)

     

    End Sub

     

    CSS

    .no

    {

        height: 24px;

        width: 24px;

        border: none;

        display: block;

        margin: 0px,0px,0px,0px;

        background-color: Transparent;

        background: url('../Images/no.png');

        background-repeat: no-repeat;

     

    }

     I have a dropdown-solution for language change that works. But I want a flag image-button, where opesite flagg is shown with the selected language.

     

    Any ideas where to bring this forward? Someone with a button-click-event that would do the job?

    Looking forward to some help here.....

     

    Tuesday, January 11, 2011 4:06 PM

Answers

  • User144738434 posted

    Hi....

     

    Have moved on with my solution. Hopefully someone will find it helpfull.

    Status now is:

    Masterpage.Master

    <div id="Logo">
       
    <asp:ImageButton ID="Image1" runat="server" PostBackUrl="~/default.aspx" meta:resourcekey="Image1Resource1"_
    ImageUrl="<%$Resources: SiteMapLocalizations, LogoMainHead%>" ImageAlign="Middle" />
                </div>

    <div id="LangugeRibbon">

    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Language1.png" AlternateText="Language1" />
    <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/Images/Language1.png" AlternateText="Language2" />
    </div> ¨

    Using App_GlobalResources/SiteMapLocalizations.resx/SiteMapLocalizations.en.resx

    With String Name: LogoMainhead - and Value suffix: ~/images/Logo1/2.png in each resource file.

    The problem now is the ClickEvent for my ImageButtons.

    My status here is:

    BaseClass.vb

    Public Class BasePage
        Inherits Page

        Protected Overrides Sub InitializeCulture()
            Dim lang As String = String.Empty

            'default to the invariant culture
            Dim cookie As HttpCookie = Request.Cookies("SelLang")

            If cookie IsNot Nothing AndAlso cookie.Value IsNot Nothing Then
                lang = cookie.Value
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang)
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang)

            End If
            MyBase.InitializeCulture()


        End Sub

    With running <Inherits BaseClass> for every aspx.vb-Page in the site.

    And in MasterPager.Master.vb I have this:

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
            Dim cookie As New HttpCookie("SelLang")
            cookie.Value = CultureInfo.CurrentCulture.CultureTypes
            Response.SetCookie(cookie)
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("nb-NO")
            Thread.CurrentThread.CurrentUICulture = New CultureInfo("nb-NO")

            Response.Write(Thread.CurrentThread.CurrentCulture)

            Dim geturl As String

            geturl = Request.Url.ToString()
            Response.Redirect(Request.UrlReferrer.AbsoluteUri)


        End Sub

     

    But when running the button-click - I have no change in the culture.??? Anyone?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 11, 2011 9:53 PM