locked
ASP:MENU control OnMenuItemDataBound event not firing after keeping system idle for some time RRS feed

  • Question

  • User1819786090 posted

    Hi,

    We have ASP:MENU control used with Sitemap file for maintaining the Menu options based on Roles.

    We have OnMenuItemDataBound event written in which we hide some menu w.r.t logged-in users role.

    Recently we are facing one issue where we can see that some users dont see menu items at all when they keep system idle for 10 minutes or so. I was able to reproduce this issue in dev environment when i kept system idle for 30 minutes. I saw that OnMenuItemDataBound event was not firing which was causing not to populate menu items.

    We found that session is not timing out here but the even itself is not getting fired.

    Please advise if any inputs on this issue.

    Thanks

    Tuesday, June 16, 2020 10:53 AM

All replies

  • User1535942433 posted

    Hi Nipane Sanjay,

    Accroding to your description,as far as I think,It doesn't matter with system idle.I create a little test and I keep systems idle for 10 min.It works fine.

    Could you post your codes to us?It will help us to solve your problems.

    Best regards,

    Yijing Sun

    Wednesday, June 17, 2020 6:06 AM
  • User1819786090 posted

    Hi,

    FOllowing is the code for Menu Item on .ASPX page

    <asp:Menu runat="server" CssClass="menu" ID="menu" DataSourceID="smdsMenu" Orientation="Horizontal"
    StaticEnableDefaultPopOutImage="false" DynamicEnableDefaultPopOutImage="false"
    DisappearAfter="1500" OnMenuItemDataBound="menu_MenuItemDataBound">
    <StaticMenuStyle CssClass="static-menu" />
    <StaticMenuItemStyle CssClass="static-menu-item" />
    <DynamicMenuItemStyle CssClass="dynamic-menu-item" />
    <DynamicMenuStyle CssClass="dynamic-menu" />
    </asp:Menu>

    And then we have event handler for hiding menu items w.r.t role

    protected void menu_MenuItemDataBound(object sender, MenuEventArgs e)
    {

    code for hiding menu items based on logged-in users role...

    }

    Wednesday, June 17, 2020 6:23 AM
  • User1535942433 posted

    Hi Nipane Sanjay,

    Accroding to your description and codes,I create a test.

    This is my codes:

    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
                <asp:Menu ID="Menu" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal"
                    OnMenuItemDataBound="Menu_MenuItemDataBound" StaticEnableDefaultPopOutImage="false" DynamicEnableDefaultPopOutImage="false"
                    DisappearAfter="1500">
                    <StaticMenuStyle CssClass="static-menu" />
                    <StaticMenuItemStyle CssClass="static-menu-item" />
                    <DynamicMenuItemStyle CssClass="dynamic-menu-item" />
                    <DynamicMenuStyle CssClass="dynamic-menu" />
                </asp:Menu>

    Code-behind:

     protected void Menu_MenuItemDataBound(object sender, MenuEventArgs e)
            {
                if (SiteMap.CurrentNode != null)
                {
                    if (e.Item.Text == SiteMap.CurrentNode.Title)
                    {
                        if (e.Item.Parent != null)
                        {
                            e.Item.Parent.Selected = true;
                        }
                        else
                        {
                            e.Item.Selected = true;
                        }
                    }
                }
            }

    Site.map:

    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
     <siteMapNode url="" title="Home" description="">
        <siteMapNode url="Home.aspx" title="Home" description="Home Page" />
        <siteMapNode url="javascript:;" title="Services" description="Services Page">
          <siteMapNode url ="Consulting.aspx" title="Consulting" description="Consulting Page"></siteMapNode>
          <siteMapNode url ="Outsourcing.aspx" title="Outsourcing" description="Outsourcing Page"></siteMapNode>
        </siteMapNode>
        <siteMapNode url="About.aspx" title="About" description="About Us Page" />
        <siteMapNode url="Contact.aspx" title="Contact" description="Contact Us Page" />
     </siteMapNode>
    </siteMap>

    I test the menu and after sleeping 10min.I open the screen and still show the menu.

    1.Wheather all of menu disappear after keeping  system idle for some time?

    2.What you do after keeping system idle before to show the menu?

    Could you tell us more details of your opeartions?

    Best regards,

    Yijing Sun

    Wednesday, June 17, 2020 9:44 AM
  • User1819786090 posted

    Thanks for the feedback.

    When I keep system idle for 20/30 minutes then I click on Switch ROle link available on Master page. This link helps to switch the role for logged-in user. So when user clicks on this then ultimately it invokes the respective link click event and then invocation goes to master page also. But OnMenuItemDataBount doesnt get invoked. Whereas in normal condition I saw that breakpoint placed in this method gets hit.

    Friday, June 19, 2020 7:26 AM
  • User1535942433 posted

    Hi Nipane Sanjay,

    As far as I think,when you change the user account,you need to recreate/refresh the menu.

    More details,you could refer to below article:

    https://forums.asp.net/t/1579082.aspx?Refresh+Menus+on+the+MasterPage+after+ContentPage+PostBack

    Best regards,

    Yijing Sun

    Tuesday, June 23, 2020 6:47 AM