Solved

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

Posted on 2010-09-23
9
846 Views
Last Modified: 2012-05-10
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>
0
Comment
Question by:GlobaLevel
  • 4
  • 3
  • 2
9 Comments
 
LVL 7

Expert Comment

by:Alpha Au
ID: 33751443
how about do it in code behind

menu.additem new menuItem(Session["sessionhome_page"])
0
 
LVL 5

Expert Comment

by:VincentSG
ID: 33752045
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")' />
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 33753434
Alphaau... Can you give an example? I'm using master pages
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
Alpha Au earned 500 total points
ID: 33766740
sorry for the late reply,

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);


hope this help!
0
 
LVL 5

Expert Comment

by:VincentSG
ID: 33766868
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") %>' />
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 33775814

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);
0
 
LVL 7

Expert Comment

by:Alpha Au
ID: 33776053
you can put it on the master page code behind

the only problem is when will you assign the session variable value?
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 33780478
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...
0
 
LVL 7

Expert Comment

by:Alpha Au
ID: 33780569
can you put the menu in the master page?
if so, you can put the code behind in master page code behind too
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net creating Contact in Outlook 1 49
asp.net mvc 2 32
Find date of 2nd Thursday of each month 3 32
Include MS Database in Winforms Project using Intellilock 5 21
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question