locked
Problem with SiteMapData-bounded controls RRS feed

  • Question

  • User558695650 posted

    Hi!

    I have a simple page with a treeview, a menu and a sitemappath controls along with a select-language listbox:

    form id="form1" runat="server">
    <div>
    <br />
    <asp:ListBox ID="ListBox1" runat="server" Rows="1">
    <asp:ListItem Value="es-MX">Espa&#241;ol</asp:ListItem>
    <asp:ListItem Value="en-US">English</asp:ListItem>
    </asp:ListBox>&nbsp;<asp:Button ID="Button1" runat="server" Text="Button" /><br />
    <br />
    <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
    </asp:TreeView>
    <hr />
    <asp:SiteMapPath ID="SiteMapPath2" runat="server">
    </asp:SiteMapPath>
    <br />
    <hr />
    <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
    </asp:Menu><br /><br />
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
    </div>
    </form>

    In the code-behind page we have the following:

    Protected Overrides Sub InitializeCulture()
    Dim ls As String = "ListBox1"
    If Not Request.Form(ls) Is Nothing Then
     
    Dim selectedLanguage As String = Request.Form(ls)

      UICulture = Request.Form(ls)
      Culture = Request.Form(ls
    )
      Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage)
      Thread.CurrentThread.CurrentUICulture =
    New CultureInfo(selectedLanguage)
    End If
    MyBase.InitializeCulture()
    End Sub

    When I select the Spanish language the only control that changes to Spanish is the SiteMapPath, but the SiteMapData-bounded controls (treeview and menu) keep in English.

    I've been trying to figure out what's wrong but cannot make them work. Any idea?

    Monday, January 30, 2006 11:29 AM

All replies

  • User558695650 posted

    Got it!

    It was driving me crazy but I finally got it! The point is that treeview, and menu (and others) are data-bound controls. So You have to update them when you need their contents to change, in this case whe you select another language.

    So finally you only have to "re-bind" the control to its data source. You cannot do it in the InitializaCulture sub because the controls aren't still created yet. What I did was to put it in the load method of the form and voila! Everything is working terrific!

    Hope this help others.

    Tuesday, January 31, 2006 10:03 AM
  • User38218365 posted

    What did you do?

    I realise this post is a bit old but I'm facing the following situation and it is also "driving me crazy".

    I have a menu control on a master page and want to switch language through implict localization (i.e. browser setting). I don't want to do this through ItemDataBound.

    The control is link to a sitemap datasource and the xml has enableLocalization="true" and a resourceKey="xxx" in each siteMapNode. Furthermore, to be sure both the sitemap control and menu control call their DataBind method on page load. Still no luck.

    Any help would be appreciated.

     

    Friday, April 28, 2006 6:11 AM