Solved

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

Posted on 2010-09-23
9
847 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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