Menu Control Questions
Menu Control Questions
Menu Control Questions
Menu Control Questions
Menu Control Questions
Menu Control Questions Menu Control Questions Menu Control Questions Menu Control Questions Menu Control Questions Menu Control Questions Menu Control Questions Menu Control Questions
Menu Control Questions Menu Control Questions
Menu Control Questions
Go Back  Xtreme Visual Basic Talk > > > Menu Control Questions


Reply
 
Thread Tools Display Modes
  #1  
Old 09-06-2006, 05:20 PM
King_George's Avatar
King_George King_George is offline
Junior Contributor
 
Join Date: Feb 2005
Location: Oakville, Ontario Canada
Posts: 353
Default Menu Control Questions


OK I have to create a menu for navigating through my site in ASP.net and Visual Studio 2005. No problem except that the menu needs to show or hide items depending on the user rights. No problem again, I've done that for one page rather easily.

Now my question is, what is the best way of creating the menu once and displaying it on every page that needs it?

I tried creating it in a class and calling the class function in the page_load event by returning the menu object but I could never make it appear on the calling page in the code-behind. In the class I created a menu object, added the submenus and all that and set attributes and then returned it. No show. When I do the same thing by simply putting the code in the class into in the page_load event, it shows and works great!! So to repeat, I don't want to put this code in every page_load in every page.

I'm kinda new to asp.net and I'm so used to having include files in classic ASP. The process I have is to log in and then when successfully logged in I want to create the menu and display it on every page. I don't want to have to code the menu for every page. We are not looking to buy a 3rd party component right now. The company wants to make it's own standard.

Thx in advance for any suggestions from the .NET noob...
__________________
Energy can neither be created or destroyed. It can only be wasted.

Red Green
Reply With Quote
  #2  
Old 09-07-2006, 07:49 AM
wayneph's Avatar
waynephMenu Control Questions wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

The easiest thing would be to just make a User Control (.ascx file extension) and put all of the code for the menu in there. Then with two lines of code in your .aspx page you can add the menu on every page.

First you need to register it:
HTML Code:
<%@Register tagprefix="MyControls" Tagname="Menu" src="menu.ascx" %>
Then you can add it to your page:
HTML Code:
<MyControls:Menu runat="Server" id="MyMenu" />
If you want to be able to customize it you can add Public Properties that accept parameters from the tag.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 09-07-2006, 09:18 AM
King_George's Avatar
King_George King_George is offline
Junior Contributor
 
Join Date: Feb 2005
Location: Oakville, Ontario Canada
Posts: 353
Default

Quote:
Originally Posted by wayneph
The easiest thing would be to just make a User Control (.ascx file extension) and put all of the code for the menu in there. Then with two lines of code in your .aspx page you can add the menu on every page.

First you need to register it:
HTML Code:
<%@Register tagprefix="MyControls" Tagname="Menu" src="menu.ascx" %>
Then you can add it to your page:
HTML Code:
<MyControls:Menu runat="Server" id="MyMenu" />
If you want to be able to customize it you can add Public Properties that accept parameters from the tag.
Thx Wayne I'll try it out as soon as I get home tonight.. Luckily there is no need for customization so I'll stick with the standard menu control for now. What I'm actually creating is a template for use with almost all the pages.

I'll cruise around for tutorials on the subject now that I know what to do

Just one more fast question if you don't mind..

Will the usercontrol have to make a call to the database every time it's used to get the user security settings or is there a good way to store these settings for use by the usercontrol? I was thinking Application variables to store the settings. Am I on the right track?

Thx again
__________________
Energy can neither be created or destroyed. It can only be wasted.

Red Green
Reply With Quote
  #4  
Old 09-07-2006, 10:33 AM
wayneph's Avatar
waynephMenu Control Questions wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

If you're creating a template and using VS 2005, I'd take this one step further. Create a Master Page that has your header/menu/footer/etc... on it with a Content Panel. Then when you're creating new pages, specify which master page it uses, and your template should follow you. with NO extra work on each page.

Yes, by default the user control will go to the database each time it is loaded. Instead of using an Application Variable I would look into the Output Caching options for the control. Then not only would it not have to go to the database, it wouldn't have to process the dataset either. It would just use the same HTML it generated last time. Even more efficient.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #5  
Old 09-07-2006, 11:12 AM
King_George's Avatar
King_George King_George is offline
Junior Contributor
 
Join Date: Feb 2005
Location: Oakville, Ontario Canada
Posts: 353
Default

Quote:
Originally Posted by wayneph
If you're creating a template and using VS 2005, I'd take this one step further. Create a Master Page that has your header/menu/footer/etc... on it with a Content Panel. Then when you're creating new pages, specify which master page it uses, and your template should follow you. with NO extra work on each page.

Yes, by default the user control will go to the database each time it is loaded. Instead of using an Application Variable I would look into the Output Caching options for the control. Then not only would it not have to go to the database, it wouldn't have to process the dataset either. It would just use the same HTML it generated last time. Even more efficient.
Thanks again, I'll be sure to let you know how this worked out.. Time to get a few books I think.
__________________
Energy can neither be created or destroyed. It can only be wasted.

Red Green
Reply With Quote
  #6  
Old 09-07-2006, 08:17 PM
King_George's Avatar
King_George King_George is offline
Junior Contributor
 
Join Date: Feb 2005
Location: Oakville, Ontario Canada
Posts: 353
Default

Thx a lot Wayne. The master page makes my job so much easier and faster. Faster by magnitudes now..

Took me all of 10 minutes to create a workable master page that has a header, footer and a dynamic menu. Using the Cache reduces the DB round trips to almost nothing. I flush the cache every 20 minutes and reload it at the next page startup in case the user's rights change.

Now the next step is to actually put some working code into the content place holder. this project suddenly is looking up..

It looks crude right now but I always get it working, then decorate.

Thx again.
__________________
Energy can neither be created or destroyed. It can only be wasted.

Red Green
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Menu Control Questions
Menu Control Questions
Menu Control Questions Menu Control Questions
Menu Control Questions
Menu Control Questions
Menu Control Questions Menu Control Questions Menu Control Questions Menu Control Questions Menu Control Questions Menu Control Questions Menu Control Questions
Menu Control Questions
Menu Control Questions
 
Menu Control Questions
Menu Control Questions
 
-->