Welcome Guest Search | Active Topics | Sign In | Register

eo.web.menu prevent from repopulating every time the master page is loaded Options
Ismael
Posted: Tuesday, February 3, 2009 4:28:50 PM
Rank: Member
Groups: Member

Joined: 2/3/2009
Posts: 28
How can I prevent the menu control from repopulating every time the master page is loaded.

I have a menu control that is loaded in to a master page, once the user login then I populate the menu control. I populate the menu control using a dataset. I have no issue populating the menu from the datase, my issue is that every time the master page is loaded it does a trip to the database and repopulates the menu control. I want to be able to minimize the trips to the database.

I tried to pupulate the menu control on the login event but nothing showed up in the menu control. After the user login he/she is redirected to a particular page and when the page is loaded the master page is reloaded, no menu items appear. I checked the menu items couts and = 0.

Is there a setting that I am missing that will save the menu items every time a new page is called (using master pages)?

One thing to keep in mind is that each user can have different menu items, menu items as based on user access rights.

Thanks in advance.
eo_support
Posted: Tuesday, February 3, 2009 4:58:19 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,089
Hi,

There are two scenarios that you might be confused about:

1. User navigating from PageA.aspx to PageB.aspx. In this case even both PageA.aspx and PageB.aspx uses the same master page MasterPage.master, the menu will need to be repopulated. This is the normal behavior;
2. User working within PageA.aspx. For example, you have a button inside PageA.aspx, user clicks it, the page goes back to the server, updates something and reloads. In this case, the menu automatically saves all items inside view state until you explicitly repopulate it unless ViewState is disabled. Usually people do this inside Page_Load to avoid repopulating during postback:

Code: C#
If (!Page.IsPostBack)
    PopulateMenu();


The key at here is as soon as a page is rendered, everything exception for cookies and sessions is gone (the key for a Web server to serve many users at the same time is that it does not keep much information in memory at all). So there is no such thing as automatically carrying control state information from PageA.aspx to PageB.aspx unless you explicitly code for it. ASP.NET retains state information within the same page with ViewState, but that only occurs when PageA.aspx goes back to PageA.aspx. When PageA.aspx goes to PageB.aspx, everything in PageA is discarded. It's the server's responsiblity to reconstruct everything from ground up based on certain informations (for example, the current loged in user ID).

Thus in your case it is quite normal that the menu is being repopulated every time. For example when you populate inside the login event, it will be discarded when the page redirects to another page. This is how it supposes to work.

There are two things you can do:
1. If you are not already using "if (!Page.IsPostBack)", you can add that so that the menu will only be populated once when a page initially load but not during postback;
2. After you get your menu data from your database, saves it inside your Session object. Later on you will still need to populate the menu every time, but instead of getting the data again from the database, you get it directly from Session object. This reduces your database server's load, but increases your Web server's memory consumption. Obviously if you use SQL Server to store session data, then this will be completely pointless;

Hope this helps. Please let us know if you still have more questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.