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

February 6th, 2012, 03:15 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
|
|
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
|
|

February 6th, 2012, 04:19 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

February 7th, 2012, 02:20 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
|
|
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
|
|

February 7th, 2012, 04:25 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

February 8th, 2012, 03:49 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
|
|
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
|
|

February 8th, 2012, 03:53 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

February 9th, 2012, 12:27 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
|
|
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
|
|

February 9th, 2012, 12:40 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
Tulsi (February 14th, 2012)
|
|

February 14th, 2012, 02:51 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
|
|
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
|
|
 |
|