Solved

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

Posted on 2010-09-23
9
843 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
Comment Utility
how about do it in code behind

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

Expert Comment

by:VincentSG
Comment Utility
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
Comment Utility
Alphaau... Can you give an example? I'm using master pages
0
 
LVL 7

Accepted Solution

by:
alphaau earned 500 total points
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 5

Expert Comment

by:VincentSG
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now