asp:menu that depends on language

Last post 06-20-2009 2:57 PM by moshicn@gmail.com. 3 replies.

Sort Posts:

  • asp:menu that depends on language

    06-20-2009, 7:08 AM

     Hi,

    I'm building a website that has two languages.
    I have a asp:menu in it , while I want to transfer the language menuItems to English while
    the selected language is English.
    I used a resourse file (with meta:resourseKey etc...) for it, and it works, but the navigateUrl property
    that doesn't work with it.
    I thought to work with siteMap - a different siteMap to each language, so that the asp:menu
    will take the menuItems from the appropriate siteMap.
    Does anyone have any idea how to do it ?
    The most important thing is that the url will work for each language.

    Thanks. 

  • Re: asp:menu that depends on language

    06-20-2009, 9:32 AM
    • All-Star
      58,112 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,654
    • Moderator

     Hi,

    What i understoond is that you have different pages for each langauge and you want to populte the menu control with the pages of the currently selected langauge , right?

    You can create two SiteMapDatasources and set the Menu datasource for one of based on the lanague .

    For Configuring multiple SiteMapDataSources , check :

    http://msdn.microsoft.com/en-us/library/ms178426.aspx

    After configuring the datasources , you can set the menu DataSourceId property in code behind based on the current language:

    for example, in Page_Laod of the masterPage:

    If(  this.Page.UICulture=="en-US")
    Menu1.DataSourceId="EnglishSiteDataSource";
    else
    Menu1.DataSourceId="OtherSiteDataSource";
      
    Regards,

    Anas Ghanem | Blog

  • Re: asp:menu that depends on language

    06-20-2009, 11:20 AM

    Well, I'm not sure i understand the meaning:
    I put in my web.config:

     <siteMap defaultProvider="HebSiteMap">
    <
    providers>
    <
    add name="HebSiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="~/SiteMap/MenuHeb.sitemap" />
    <
    add name="EngSiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="~/SiteMap/MenuEng.sitemap" />
    </
    providers>
    </
    siteMap>

    In my Master page, where I want the menu, I have:

    <asp:Menu ID="MainMenu" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" Width="600px"></asp:Menu>
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />

    And in my code I have:

    SiteMapDataSource1.SiteMapProvider = ConfigurationManager.AppSettings["EngSiteMap"];

    But I still get the "defaultProvider" from the web.config

    But what do I miss ?

  • Re: asp:menu that depends on language

    06-20-2009, 2:57 PM
    Answer

    OK I have the solution:

    SiteMapDataSource1.SiteMapProvider = "EngSiteMap";

    and he recognizes it.

    Thank you so much !

Page 1 of 1 (4 items)