Solved

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

Posted on 2010-09-23
9
844 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:alphaau
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 7

Accepted Solution

by:
alphaau 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:alphaau
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:alphaau
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 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