0

I am currently adding functionality in a website that uses the Menu web control.

Within the website there are different roles which require a different set of navigation options to appear depending on that role, to complete this task I have added a function to the code behind of the master page that is called from the Page_Load that takes a file name (sitemap) as a parameter and binds the menu that is in the html to this source.

My problem is that when I navigate to a page that does not exist and then go back the menu no longer appears.

Can anybody give me any information on this issue such as why it is happening and a resolution to it, also this problem only seems to happen in Internet Explorer 9 out of Firefox, Opera and Chrome.

My Current Code is the following.

    Menu menu = new Menu();
    menu.Orientation = Orientation.Horizontal;
    menu.StaticDisplayLevels = 2;
    menu.MaximumDynamicDisplayLevels = 3;
    menu.CssClass = "menu";
    menu.EnableViewState = false;

    //configure xmldatasource
    XmlDataSource xmlDS = GetSiteMapDataSource(navigationPath);
    xmlDS.XPath = "/*/*";
    xmlDS.EnableCaching = false;

    //configure menuitembinding
    MenuItemBinding mib = new MenuItemBinding();
    mib.DataMember = "siteMapNode";
    mib.TextField = "title";
    mib.NavigateUrlField = "url";
    mib.ValueField = "title";

    //configure datasource
    menu.DataSource = xmlDS;
    menu.DataBindings.Add(mib);
    menu.DataBind();

    //add to panel
    NavigationPanel.Controls.Add(menu);  

This is my code as current not including css related information, I am currently having a go at using SiteMapDataSource as opposed to XMLDataSource as I believe I may be able to use the following information from my web config file to select the data source.

    <siteMap defaultProvider="guest">
        <providers>
            <add name="guest" type="System.Web.XmlSiteMapProvider" siteMapFile="~/App_Data/Guest.sitemap"/>
            <add name="professional" type="System.Web.XmlSiteMapProvider" siteMapFile="~/App_Data/Professional.sitemap"/>
            <add name="supplier" type="System.Web.XmlSiteMapProvider" siteMapFile="~/App_Data/Supplier.sitemap"/>
        </providers>
    </siteMap>

Thanks,

Ric.

casperOne
  • 73,706
  • 19
  • 184
  • 253
RJF
  • 141
  • 1
  • 3
  • 12

1 Answers1

0

The code should only be executed when there's not a postback.

If (!IsPostBack)
{
    //Your code here!
}

Otherwise, your elements will be deleted.

Vivas84
  • 111
  • 1