Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 6th, 2012, 03:15 PM
Friend of Wrox
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default Chapter 7 - Menu question

Hi Imar,

I had a question with the menu....

p. 254 --> I added the styling for the menu to the css file as described on this page. When I run the app, I noticed that the "home" menu item is hilited blue (and therefore selected) by default everytime u start the application. Is this supposed to happen?

Thank you.

Tulsi
 
Old February 6th, 2012, 04:19 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Yes, that's by design. ASP.NET adds the CSS class "selected" to the menu item that belongs to the current page. The CSS code then gives this menu a different color:

Code:
ul.level1 .selected { /* Defines the appearance of active menu items */ background-color: #BCD1FE;
}
Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 7th, 2012, 02:20 PM
Friend of Wrox
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Let's say I wanted the "login" menu item to be the default selected item when the site first runs, is there a way to do this?

Thanks,
Tulsi
 
Old February 7th, 2012, 04:25 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Do you want to the menu to be highlighted, or do you want the Login page to be the default page that loads up?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 8th, 2012, 03:49 PM
Friend of Wrox
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

I wanted the menu item to be highlighted upon startup of the app. So let's say the "About menu item" is automatically highlighted by default when the app first runs.

Thank you.

Tulsi
 
Old February 8th, 2012, 03:53 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I understand that. But do you want to highlight it because Login becomes the default page, or do you want to highlight Login even Default.aspx / Home is the currently active page? The latter doesn't make so much sense to me; normally you highlight menu items to indicate which item is currently being displayed.

Cheers.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 9th, 2012, 12:27 PM
Friend of Wrox
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Sorry for the confusion. You are right, I was hoping I could highlight it because Login becomes the default page.

Thank you for your help.

Tulsi
 
Old February 9th, 2012, 12:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In that case, you have a few options depending on what you want to implement.

1. If you want the Login page to be the default page because you want to block access to all pages for users that are not logged in, add something like this to your web.config:

<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>

This blocks access to all anonymous users; .NET will then redirect them to the Login page.

In case you just want it to make the default while still allowing access to the other pages, you have some other options:

2. In Session_Start in Global.asax you can also redirect the user through code, using something like:

Response.Redirect("~/Login.aspx)

3. The simplest solution would be to rename Login.aspx to Default.aspx. For that yo work, you may also need to set the login page in web.config as it defaults to Login.aspx:

<authentication mode="Forms">
<forms loginUrl="~/Default.aspx" timeout="2880" />
</authentication>

4. A final solution would be to configure IIS and make Login.aspx the preferred default document over Default.aspx. Not really recommended though.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Tulsi (February 14th, 2012)
 
Old February 14th, 2012, 02:51 PM
Friend of Wrox
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Thank you for providing all of these options. It's good to know that there are multiple ways to do this.

This information is very helpful. Thank you again.

Tulsi





Similar Threads
Thread Thread Starter Forum Replies Last Post
Start menu _ Recent Projects general question allken BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 October 11th, 2011 10:31 AM
Chapter 7 - Creating Menu dvirdukhan BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 8 May 18th, 2011 04:42 PM
Question on sub menu items not appearing. leemark2k3 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 10 February 17th, 2011 08:00 AM
Question on Horizontal Menu RinoDM CSS Cascading Style Sheets 1 March 11th, 2008 11:45 PM
<asp:menu question paco ASP.NET 2.0 Professional 0 August 22nd, 2006 08:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.