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:
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:
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?
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:
Code:
if (!Page.IsPostBack)
{
string selectedTheme = Page.Theme;
HttpCookie preferredTheme = Request.Cookies.Get("preferredTheme");
if (preferredTheme != null)
{
selectedTheme = preferredTheme.Value;
if (preferredTheme.Value == "DarkGrey")
{
Menu1.Orientation = Orientation.Vertical;
}
else { Menu1.Orientation = Orientation.Horizontal; }
}
if (!string.IsNullOrEmpty(selectedTheme) && ThemeList.Items.FindByValue(selectedTheme) != null)
{
ThemeList.Items.FindByValue(selectedTheme).Selected = true;
}
}
}
Code:
if (!Page.IsPostBack)
{
string selectedTheme = Page.Theme;
HttpCookie preferredTheme = Request.Cookies.Get("preferredTheme");
if (preferredTheme != null)
{
selectedTheme = preferredTheme.Value;
}
}
if (!string.IsNullOrEmpty(selectedTheme) && ThemeList.Items.FindByValue(selectedTheme) != null)
{
ThemeList.Items.FindByValue(selectedTheme).Selected = true;
}
}
switch (Page.Theme.ToLower())
{
case "darkgrey":
Menu1.Visible = false;
TreeView1.Visible = true;
break;
default:
Menu1.Visible = true;
TreeView1.Visible = false;
break;
}
}
Comment