I'll keep this simple. For development purposes I want to create "modes" representing various user types which will see a different menu bar accordingly. I've got everything the way I want it except after selecting the "mode" in which I wish to operate, as soon as I click on a menu item, it forgets which "mode" it was in and refreshes with the default menu bar. I'm assuming this is an issue with ViewState not maintaining properly over the postback? I've searched all over the forums and elsewhere and can't figure out how to accomplish what I want. Here is my code with codebehind.
I added the following to Page_Load:
If Not IsPostBack Then
modeMenu.SelectedValue = Session("mode")
End If
EDIT: The rest is the same with the exception of one additional line in the code behind. Thanks to TC for the answer :)
<asp:Menu ID="mode1Nav" runat="server" CssClass="menu"
Visible="False" ViewStateMode="Enabled">
<Items>
<asp:MenuItem NavigateUrl="~/Home1.aspx" />
<asp:MenuItem NavigateUrl="~/DoSomething1.aspx" />
</Items>
</asp:Menu>
<asp:Menu ID="mode2Nav" runat="server" CssClass="menu"
Visible="False">
<Items>
<asp:MenuItem NavigateUrl="~/Home2.aspx" />
<asp:MenuItem NavigateUrl="~/DoSomething2.aspx" />
</Items>
</asp:Menu>
This "modeMenu" is used to select my mode.
<asp:DropDownList ID="modeMenu" runat="server" AutoPostBack="True"
ViewStateMode="Enabled" CssClass="modeMenu">
<asp:ListItem>Mode1</asp:ListItem>
<asp:ListItem>Mode2</asp:ListItem>
</asp:DropDownList>
This code behind Sub is intended to display the appropriate menu for whatever mode your in, AND REMEMBER IT, lol.
Protected Sub mode(ByVal sender As Object, ByVal e As System.EventArgs) Handles modeMenu.Load, modeMenu.SelectedIndexChanged
Session.Add("mode", modeMenu.SelectedValue) //Added this
Select Case (modeMenu.SelectedValue)
Case "Mode1"
mode1Nav.Visible = True
mode2Nav.Visible = False
Case "Mode2"
mode1Nav.Visible = False
mode2Nav.Visible = True
End Select
End Sub
Like I said, the problem is that after selecting my mode, once I try to use the menu, it refreshes and forgets the mode.
EDIT: Additionally I added the following CSS to put my mode menu out of the way. It works quite nicely like this. Really handy for development. :)
.modeMenu {
position: fixed;
top: 5px;
left: 5px;
}