locked
Populate Menu RRS feed

  • Question

  • User-158363518 posted

    hi

    I have a program containing 50 pages.

    I have a static menu in them.

    When changing the menu, I must edit 50 pages

    If I want to read and display my menu from the database

    When the user is browsing between pages

    cost a lot

    Because each time you need to get a menu from the database

    What is the quick solution to this?

    Friday, June 22, 2018 4:29 PM

Answers

  • User-1171043462 posted

    Populate the menu from database only. But lazy load it after complete page is loaded using AJAX.

    This won't slow it down.

    Also you can load the menu into some Generic collection or DataTable and then store in Cache. And retrieving from cache will be even more faster.

    Populating Menu items from the Database in ASP.Net using C# and VB.Net

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 23, 2018 12:57 PM
  • User-1171043462 posted

    Frankly speaking there is no Fast or Quick way.

    You will have to do some work as you are using Static menu for 50 pages.

    If you don't want ASP control, you can use Repeater and use your existing menu.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 23, 2018 7:24 PM
  • User-1171043462 posted
    Cache will usw the ram of your server.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2018 4:55 PM

All replies

  • User475983607 posted

    What is the quick solution to this?

    Cache the menu.

    https://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache(v=vs.110).aspx

    Friday, June 22, 2018 5:20 PM
  • User-158363518 posted

    Is there a sample code for its implementation?

    Friday, June 22, 2018 5:46 PM
  • User475983607 posted

    Is there a sample code for its implementation?

    The linked document has source code that explains how to read and write cache data which should answer your original question.

    However, the design is totally up to you and really this design question cannot be answered on a forum as there are too many open questions.  However, there are plenty of examples on the Internet that are just a search away.

    https://www.mikesdotnetting.com/article/255/entity-framework-recipe-hierarchical-data-management

    https://www.mikesdotnetting.com/article/208/practical-recursion-in-asp-net-web-pages-with-webmatrix

    ASP.NET  has a built in menu control which you might take a look at.

    https://msdn.microsoft.com/en-us/library/ecs0x9w5.aspx

    https://msdn.microsoft.com/en-us/library/305w735z.aspx

    Friday, June 22, 2018 6:03 PM
  • User-1171043462 posted

    Populate the menu from database only. But lazy load it after complete page is loaded using AJAX.

    This won't slow it down.

    Also you can load the menu into some Generic collection or DataTable and then store in Cache. And retrieving from cache will be even more faster.

    Populating Menu items from the Database in ASP.Net using C# and VB.Net

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 23, 2018 12:57 PM
  • User-158363518 posted

    Thank you very much for your help and advice.

    I will provide more clarification for clarification

    i have a static sideBar Menu that have 50 item .

    thats mean i have 50 pages .

    When changing the menu, I must edit 50 pages

    If I want to read and display my menu from the database

    When the user is browsing between pages

    cost a lot

    Because each time you need to get a menu from the database

    What is the quick solution to this?

    i want generate this menu with this structure.

    asp menu has additional css class and i cant customize that to this sample well .

    like this :

    <ul>
    <li><a class="right-align" href="#"><i class="fa fa-dashboard pink-item"></i>dashboard</a></li>
    <li>
    <div class="divider"></div>
    </li>

    <li class="no-padding">
    <a class="collapsible-header right-align" href="item1.aspx">item1<i class="fa fa-edit"></i></a>
    </li>
    <li class="no-padding">
    <a class="collapsible-header right-align" href="item2.aspx">item2<i class="fa fa-edit"></i></a>
    </li>
    <li class="no-padding">
    <a class="collapsible-header right-align" href="item3.aspx">item3<i class="fa fa-edit"></i></a>
    </li>
    <li class="no-padding">
    <a class="collapsible-header right-align" href="item4.aspx">item4 <i class="fa fa-edit"></i></a>
    </li>
    <li class="no-padding">
    <a class="collapsible-header right-align" href="item5.aspx">item5<i class="fa fa-edit"></i></a>
    </li>
    <li>
    <div class="divider"></div>
    </li>
    <li><a class="collapsible-header right-align" href="../Login.aspx"><i class="fa fa-sign-out pink-item"></i>exit</a></li>
    </ul>

    # - When users visit their user panel page.
      Does page download speeds down?
    Will the high number of users slow down the running of the program?

    #- if i want get a menu for each user , Should I use caching again ?  example (item1-10) for user 1 

    #- Is saving my menu in a database a good way?
    #- Or is there a faster way ?

    Saturday, June 23, 2018 4:01 PM
  • User-1171043462 posted

    Frankly speaking there is no Fast or Quick way.

    You will have to do some work as you are using Static menu for 50 pages.

    If you don't want ASP control, you can use Repeater and use your existing menu.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 23, 2018 7:24 PM
  • User-158363518 posted

    Okay, thank you.

    I want to use Repeater .

    Each user has access to a section of the menu .

    Should I do this for any user menu? (Cashing data table)

    Does it occupy a lot of memory?

    public DataTable GetDataTableFromCacheOrDatabase()
    {
       DataTable dataTable = HttpContext.Current.Cache["secret key"] as DataTable;
       if(dataTable == null)
       {
           dataTable = GetDataTableFromDatabase();
           HttpContext.Current.Cache["secret key"] = dataTable;
    // write command Expiration cash ? in this place ? (place 1)
    } return dataTable; }

    Where should we write this command? In (place 1) ?

    HttpContext.Current.Cache.Insert("secret key", dataTable, null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration);

    Do I need to make changes to the web config too ?

    Saturday, June 23, 2018 8:14 PM
  • User-1171043462 posted
    Cache will usw the ram of your server.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2018 4:55 PM