Link to home
Start Free TrialLog in
Avatar of GlobaLevel
GlobaLevelFlag for United States of America

asked on

asp.net - session varaible error in asp:menu control

I get an error...Session("sessionhome_page"

instead of this:
 <asp:MenuItem NavigateUrl="~/Local Control Panel.aspx" Text="Local Control Panel" Value="Local Control Panel">              
                    </asp:MenuItem>



I want to do this:
   <asp:MenuItem Session("sessionhome_page")>              
                    </asp:MenuItem>
Avatar of Alpha Au
Alpha Au
Flag of Hong Kong image

how about do it in code behind

menu.additem new menuItem(Session["sessionhome_page"])
Hi GlobaLevel,

Perhaps you may want to store just the URL:

<asp:MenuItem NavigateUrl='Session("sessionhome_page_url")' Text="Local Control Panel" Value="Local Control Panel" />

Or break them up into 3 different variables so that you can use:

<asp:MenuItem NavigateUrl='Session("sessionhome_page_url")' Text='Session("sessionhome_page_text")' Value='Session("sessionhome_page_value")' />
Avatar of GlobaLevel

ASKER

Alphaau... Can you give an example? I'm using master pages
ASKER CERTIFIED SOLUTION
Avatar of Alpha Au
Alpha Au
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi!

Sorry for the wrong code posted, please view the modified code below:


<asp:MenuItem NavigateUrl='<%# Session("sessionhome_page_url") %>' Text="Local Control Panel" Value="Local Control Panel" />

Or break them up into 3 different variables so that you can use:

<asp:MenuItem NavigateUrl='<%# Session("sessionhome_page_url") %>' Text='<%# Session("sessionhome_page_text") %>' Value='<%# Session("sessionhome_page_value") %>' />

I like this....but I have to add it to every page where this a menu item....... I was hoping with the session varabile just have it on one page the code behind

assume you define a menu in the aspx
<asp:Menu runat="server" ID="Mnutest"></asp:Menu>

in the code behind, you can add the following in Page_Load
            MenuItem tmpitem = new MenuItem();
            tmpitem.Text = Session["sessionhome_page_text"];
            tmpitem.Value = Session["sessionhome_page_value"];
            tmpitem.NavigateUrl = Session["sessionhome_page_url"];

            this.Mnutest.Items.Add(tmpitem);
you can put it on the master page code behind

the only problem is when will you assign the session variable value?
I have a main page that is set as the start page...when the site opens all the session varaibles are set on this page then as other pages are open...the varaibles are already set...
can you put the menu in the master page?
if so, you can put the code behind in master page code behind too