locked
localization website vb with on click flag RRS feed

  • Question

  • User420957388 posted

     hi , 

    I am working in making a multi_language site with vb.net just by  clicking on the flag of country. So  I started by adding  in my app_localressources  the files resx coding in my master page the following code: 

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
    Dim selectedLanguage As String
    selectedLanguage = "en-US"
       
    Dim cookie As New HttpCookie("CultureInfo")

     cookie.Value = selectedLanguage
      Response.Cookies.Add(cookie)

      Response.redirect(Request.Path)
    End Sub




    Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
    Dim selectedLanguage As String
    selectedLanguage = "fr-FR"
       
    Dim cookie As New HttpCookie("CultureInfo")

     cookie.Value = selectedLanguage
      Response.Cookies.Add(cookie)

      Response.redirect(Request.Path)
    End Sub
      for the default page code:


    Protected Overrides Sub InitializeCulture()

        Dim cookie As HttpCookie = Request.Cookies("CultureInfo")

    If (Not (cookie.Value Is Nothing)) Then


    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cookie.Value)
    Thread.CurrentThread.CurrentUICulture = New CultureInfo(cookie.Value)
    Else
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR")
    Thread.CurrentThread.CurrentUICulture = New CultureInfo("fr-FR")

       
    End If

    MyBase.InitializeCulture()


      End Sub.

    when i run it , an error :Handles clause requires WithEvents variable defined in the containing type or one of its basic types.(but it make the translation when i just select on flags :this way when i forced him to ignore the error ).

    can someone have an idea of this problem ? 

     

    Wednesday, May 12, 2010 11:34 AM

Answers

  • User197322208 posted

    have the control image in my masterpage.master

    SO I think then your code should be in master, not in default ..

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 13, 2010 4:41 AM

All replies

  • User197322208 posted

    what is the declaration of

    ImageButton1

    in aspx page?

    Wednesday, May 12, 2010 1:51 PM
  • User420957388 posted

    hi ignatandrei,

    for the imageButton i declared it as :Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton

    here my page aspx:

    Partial Class _Default
        Inherits System.Web.UI.Page

       
        Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton
        Protected WithEvents ImageButton2 As System.Web.UI.WebControls.ImageButton
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        End Sub
        

        Protected Overrides Sub InitializeCulture()

            'Dim session
            Dim cookie As HttpCookie


            cookie = Request.Cookies("CultureInfo")

            Try

                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cookie.Value)
                Thread.CurrentThread.CurrentUICulture = New CultureInfo(cookie.Value)


            Catch ex As Exception

            End Try

        End Sub

    End Class

    but even it is declared in aspx, i have error in masterpage.

    how can i pass the control from the master page to my aspx page??

    thanks for your help


    Wednesday, May 12, 2010 7:49 PM
  • User197322208 posted

    I want the declaration in aspx, not in aspx.cs

    <asp:imagebutton ....

    Thursday, May 13, 2010 12:55 AM
  • User420957388 posted

     

    hi ignatandrei,

     i have the control image in my masterpage.master and just by clicking on the flag image on the masterpage, i will see the result in the other pages like default.aspx.

     i have my control in  the masterpage.master so it is declared :

    <asp:ImageButton ID="ImageButton1" runat="server" AlternateText="English"
    Height="19px" ImageUrl="~/images/english.PNG" style="margin-left: 5px" />
    <asp:ImageButton ID="ImageButton2" runat="server" Height="21px"
    ImageUrl="~/images/france.PNG" Width="26px" />
     

    Thursday, May 13, 2010 4:27 AM
  • User197322208 posted

    have the control image in my masterpage.master

    SO I think then your code should be in master, not in default ..

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 13, 2010 4:41 AM