473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What is the best way to display a website navigation menu in C#?

103 100+
Below are two code samples.

I am practicing with Menu navigation and have two themes where if theme 1 the Menu is horizontal and theme 2 it is vertical. The code looks like this:
Expand|Select|Wrap|Line Numbers
  1.     if (!Page.IsPostBack)
  2.     {
  3.       string selectedTheme = Page.Theme;
  4.       HttpCookie preferredTheme = Request.Cookies.Get("preferredTheme");
  5.       if (preferredTheme != null)
  6.       {
  7.         selectedTheme = preferredTheme.Value;
  8.         if (preferredTheme.Value == "DarkGrey")
  9.         {
  10.           Menu1.Orientation = Orientation.Vertical;
  11.         }
  12.         else { Menu1.Orientation = Orientation.Horizontal; }
  13.       }
  14.       if (!string.IsNullOrEmpty(selectedTheme) && ThemeList.Items.FindByValue(selectedTheme) != null)
  15.       {
  16.         ThemeList.Items.FindByValue(selectedTheme).Selected = true;
  17.       }
  18.     }
  19.      }
If I added a treeview as well and if theme 1 then menu1 is visible and treeview is not. If theme 2 then vice versa where the code looks like this:
Expand|Select|Wrap|Line Numbers
  1.     if (!Page.IsPostBack)
  2.     {
  3.       string selectedTheme = Page.Theme;
  4.       HttpCookie preferredTheme = Request.Cookies.Get("preferredTheme");
  5.       if (preferredTheme != null)
  6.       {
  7.         selectedTheme = preferredTheme.Value;
  8.       }
  9.       }
  10.       if (!string.IsNullOrEmpty(selectedTheme) && ThemeList.Items.FindByValue(selectedTheme) != null)
  11.       {
  12.         ThemeList.Items.FindByValue(selectedTheme).Selected = true;
  13.       }
  14.     }
  15.     switch (Page.Theme.ToLower())
  16.     {
  17.       case "darkgrey":
  18.         Menu1.Visible = false;
  19.         TreeView1.Visible = true;
  20.         break;
  21.       default:
  22.         Menu1.Visible = true;
  23.         TreeView1.Visible = false;
  24.         break;
  25.     }
  26.   }
I would like to know what would be the better way of doing it or to say a best practice because either way works. How would you do it and why?
Jul 31 '12 #1
2 1825
Using a sitemap with Security TrimmingEnabled = "true" is a good solution.

Two other alternatives to consider are:

1)Move the code to build the menu into the Master Page.

2)Create a base class (public class BasePage : System.Web.UI.Page) and inherit all your pages from that base class. Put the code to build the menu into the base class.
http://www.dapfor.com/en/net-suite/n...rs-and-columns
Aug 14 '12 #2
Brian Connelly
103 100+
I have actually do have a master page and a basepage and my code is in the base page. So the code above actually lives in the basepage. I was wondering which of the above samples would be the better way of doing something. I appreciate your response and will look into the Security TrimmingEnabled = "true
Aug 19 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bryan | last post by:
I've been trying to figure out how to do this for the past 2 days and am finally tossing in the towel. No matter what I do, I just can't seem to get it to work and haven't been able to find any...
1
by: ngoc | last post by:
Hi I want to build dropdown navigation menu. Searching from google gives many commercial programs -> Not easy to choose. And I want to make it myself. Are there any good tutorials to build...
10
by: H.S. | last post by:
Hi, Let me begin by saying that I am not an HTML expert. The most experience I have for HTML authoring is when I made my webpages in my grad studies at my university and some on my home computer...
1
by: Arielle | last post by:
I know what I want. That's the first step right? Now the question is... is it possible. Using embedded unordered lists I want to display a horizontal navigation menu with potential sub-menus...
4
by: tburger | last post by:
Hey everyone- This is my first post at The Scripts, but I've used the forums before for other programming issues. Hopefully, someone has some solid styling advice for me. I've now been dealing...
2
by: klaydze | last post by:
hi, i am creating a simple website and i want to create a menu just like the other website that i see.. ok this is what i want in my menu.. i have a menu namely HOME, LIBRARY, LEARN, DOWNLOAD,...
1
by: Fabx | last post by:
Hallo, sorry for my english. I want to build a navigation menu with the repeat control, the items of menu are in a table of database. All items of the menu have class="MenuLink", but the...
1
by: Harlan Messinger | last post by:
I'm sure this is covered on the Web, but I can't figure out a sufficiently narrow Google query: Suppose I have a hierarchical website structure Page 1 Page 1a Page 1b Page 1b1 Page 1b2 Page...
1
by: Dave | last post by:
Hello, I'm working on a new site and i'd like to have a navigation menu on it. Ideally i'm thinking: home first item second item etc obviously with different names. I could use echo to...
1
by: jevic | last post by:
I am having a bit of trouble with the navigation menu on the sample website I am currently creating. The menu fits perfectly when firefox is fully sized but when I resize the browser the menu always...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.