Page view counter

Menu Control with XmlDataSource not refreshing

Last post 04-20-2009 7:53 AM by vivek.phadke. 8 replies.

Sort Posts:

  • Menu Control with XmlDataSource not refreshing

    03-27-2008, 3:08 PM
    • Loading...
    • baggadonuts
    • Joined on 05-09-2007, 3:28 PM
    • Posts 9
    • Points 0

    I have an issue with my Menu control not refreshing.. it behaves as if it's being cached or something.  My menu is being loaded from an XmlDataSource which defines the conditions when certain menu items should be enabled or disabled. 

    Hopefully this won't be too confusing... If i load a page that has a menu item enabled, switch to a condition in my application that makes that item disabled, it's still enabled on that page.  (for what it's worth, the condition is changing a database environment)... Anyway, if i navigate to another page that hasn't been viewed yet, it is properly disabled. But, even when i navigate back to the first page, it's still incorrectly enabled.  if i edit that page and refresh it, then it's properly disabled.  so it seems to me like a cache issue, but i have no caching on the site at all. 

    My source is below.  I've tried setting the datasource of the menu control to null, setting it back to the xmldatasource, and rebinding the data on every page_load, but that doesn't work.  This is just a simple web user control and i place it on a page.. The code is EXECUTING in the !Page.IsPostback block in the user control, but the menu itself is not refreshing.  any ideas? 

     

    Menu Control

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Menu.ascx.cs" Inherits="MyApp.Controls.Menu" %>
    <asp:Menu ID="MenuMain" runat="server" datasourceid="XmlDataSourceMain" orientation="horizontal">
        <DataBindings>
            <asp:MenuItemBinding DataMember="siteMapNode" TextField="title" NavigateUrlField="url" enabledfield="enabled" />
        </DataBindings>
    </asp:Menu>

    <asp:xmldatasource runat="server" id="XmlDataSourceMain" xpath="siteMap/siteMapNode" />

     

    Menu Codebehind

     

    protected void Page_Load(object sender, EventArgs e)
    {
    	if (!Page.IsPostBack) {
    		SetSecurity();
    		XmlDataSourceMain.Data = GetMenuData();
    	}
    }
    
    protected string GetMenuData()
    {
    	XmlDocument xmlDoc = LoadMenuConfigFile();
    	XPathNavigator navigator = xmlDoc.CreateNavigator();
    
    	XPathNodeIterator iterator = navigator.SelectDescendants("siteMapNode", String.Empty, false);
    	while (iterator.MoveNext()) {
    		bool enabled = false;
    
    		string roles = iterator.Current.GetAttribute("roles", String.Empty);
    		if (!StringUtil.IsBlank(roles)) {
    			enabled = IsInRoleList(roles);
    		}
    
    		if (enabled) {
    			string environments = iterator.Current.GetAttribute("environments", string.Empty);
    			if (!StringUtil.IsBlank(environments)) {
    				enabled = IsInEnvironment(environments);
    			}
    		}
    
    		iterator.Current.CreateAttribute(String.Empty, "enabled", String.Empty, enabled.ToString());
    	}
    	
    	return navigator.OuterXml;
    }
     

     

  • Re: Menu Control with XmlDataSource not refreshing

    03-27-2008, 6:09 PM
    • Loading...
    • anas
    • Joined on 09-21-2006, 4:31 AM
    • Ramallah, Palestine
    • Posts 6,115
    • Points 48,415
    • Moderator

    try to disable page cache by adding the following line to page load :

    Response.Cache.SetCacheability(HttpCacheability.NoCache)

     

    and you may need to call

     MenuMain.DataBind() to apply the changes to the menu ..

    Regards,

    Anas Ghanem.


    Note:Please Don't hesitate to click "Alert Moderators" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

  • Re: Menu Control with XmlDataSource not refreshing

    03-28-2008, 1:03 PM
    • Loading...
    • baggadonuts
    • Joined on 05-09-2007, 3:28 PM
    • Posts 9
    • Points 0

    yea i tried both of those.. didn't work.  i set the cacheability to nocache in the control and on the master page.. also on the master page i added the following... to no avail.

    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">

  • Re: Menu Control with XmlDataSource not refreshing

    03-28-2008, 1:22 PM
    • Loading...
    • anas
    • Joined on 09-21-2006, 4:31 AM
    • Ramallah, Palestine
    • Posts 6,115
    • Points 48,415
    • Moderator

    I think you have to check LoadMenuConfigFile  method ! are you using caching inside it ? FileDependancy ? when you change the data , did you clear the cache ?

     

    Regards,

    Anas Ghanem.


    Note:Please Don't hesitate to click "Alert Moderators" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

  • Re: Menu Control with XmlDataSource not refreshing

    03-29-2008, 1:46 PM
    Answer
    • Loading...
    • baggadonuts
    • Joined on 05-09-2007, 3:28 PM
    • Posts 9
    • Points 0

    I've solved this.  Was a 2 part fix. 

    1. I needed to DataBind() the XmlDataSource control 
    2. There's a setcacheability property in the XmlDataSource control

  • Re: Menu Control with XmlDataSource not refreshing

    06-03-2008, 2:43 PM
    • Loading...
    • sudhirkatiyar
    • Joined on 12-06-2006, 10:06 PM
    • Posts 5
    • Points 11

    my issue was also related to Cache. Thanks a bunch for your post

  • Re: Menu Control with XmlDataSource not refreshing

    07-21-2008, 10:34 AM
    • Loading...
    • chenthil_it
    • Joined on 07-08-2008, 9:01 AM
    • Pune
    • Posts 290
    • Points 1,490

    My issue was exactly the same and solved it after seeing this post.

    Thanks

  • Re: Menu Control with XmlDataSource not refreshing

    08-15-2008, 2:16 PM
    • Loading...
    • jgpratt01
    • Joined on 08-15-2008, 6:10 PM
    • Posts 1
    • Points 2

    My fix based on this was specifically disabling the the XmlDataSource Caching with:

    <asp:XmlDataSource ID="xmlDataSource" EnableCaching="false"

    Thanks! 

     

  • Re: Menu Control with XmlDataSource not refreshing

    04-20-2009, 7:53 AM
    • Loading...
    • vivek.phadke
    • Joined on 12-27-2007, 2:37 PM
    • Pune, India
    • Posts 27
    • Points 92

    baggadonuts,

    Thanks for the solution. point 2 did the trick for me.

Page 1 of 1 (9 items)