-1

I have created dynamic menu on the basis of user's permissions and module assigned, which has loop and if - else statements. This menu creation is in Header.ascx which is included in all the pages.

So menu creation logic executes on every page load. I want to avoid this execution on every page.

Any good suggestions to improve my implementation.

Note: menu is user specific.

Kash
  • 245
  • 1
  • 4
  • 14

3 Answers3

1

If the code is already inside a user control, you can use ASP.NET User Control caching:

http://msdn.microsoft.com/en-us/library/hdxfb6cy.aspx(link no longer valid)

http://msdn.microsoft.com/en-us/library/h30h475z(v=vs.100).aspx (updated link)

Dave Simione
  • 1,441
  • 2
  • 21
  • 31
0

Why not store the generated menu inside of the session, and only build the menu if the session value isn't present? This will increase memory consumption by your application, but increase runtime performance.

Bryan Boettcher
  • 4,412
  • 1
  • 28
  • 49
  • I want to avoid using session, any other solution! and can you tell me some other way of creating menu. I also want to avoid loop and if-else conditions. – Kash Mar 02 '12 at 20:06
  • 1
    @Kash, if you didn't want to use the session, you should have said that in your post. Also, what's wrong with loops and conditionals to build the menu? Loops and conditionals are a fundamental building block of all languages, there's noting wrong with them. Post some code if you think it could be improved. – Bryan Boettcher Mar 02 '12 at 20:10
0

In some of our applications, we use:

  • A session (app that have no sessions, only this one) to keep our control menu in memory or;
  • A session to keep your data, and just build your menu, without get your data every postback or;
  • We just do like you and put it on the Page_Load.

This will depend on how you are getting your data and how big are this data.

Lukinha RS
  • 410
  • 4
  • 12