Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 8th, 2008, 10:16 AM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 7: Navigation - Menu Control

How can I set the background colour to #c1e4ce on the menu item while I am on a page from the sub menu item.

eg. Having the background #c1e4ce for the Reviews Menu while I'm on the AllByGenre.aspx page.

I've tried added a new style on the allbygenre.aspx page but i can't get it to work.

Reply With Quote
  #2 (permalink)  
Old April 8th, 2008, 04:11 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hmmmm, not even sure if this is possible without dirty coding or style tricks.

You'd expect that StaticSelectedStyle would be in effect. However, that only applies to static leaves; not menu items that appear in between. Normally, with other dynamic menus (like the one used in the CMS Dynamicweb) you have something like IsInPath to determine if a sub item is also "in the path" to the selected item and act upon that information.

Other than programming your way out of this, you could take another, dirtier route. Each menu item has an ID. For example, Reviews has ctl00_Menu1_4 so you could address it directly:

ctl00_Menu1_4
{
  background-color: #c1e4ce;
}

Not charming, and may break as soon as you start moving things around, but it may work....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #3 (permalink)  
Old April 8th, 2008, 09:16 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Darn, I couldn't even get that to work.

It would even be neater if one could mix the menu and treeview navigation controls having them both show on the same page.

As an example, when I click on the reviews link, it will show the sub menus on a sidebar. And when you click on a sidebar menu item, the reviews link background would still be highlighted in #c1e4ce.

I do this all the time but only when using html and css. I'm sure an advanced programmer could create such a control.

Thanks Imar,

Terry



Reply With Quote
  #4 (permalink)  
Old April 9th, 2008, 04:22 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Sorry, forgot a #:

#ctl00_Menu1_4
{
  background-color: #c1e4ce;
}

You may be able to accomplish what you want with settings like StartingNodeOffset on the SiteMapDataSource control. Haven't tried this, though....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #5 (permalink)  
Old April 9th, 2008, 03:08 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's what I thought you meant. I added in the in AllByGenre.aspx

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
#ctl00_Menu1_4
{
    background-color: #c1e4ce;
}
</style>

</asp:Content>

But I thought that the <pages theme="Monochrome"> in the Web.config file wasn't allowing me to override the style so I changed it to <pages styleSheetTheme="Monochrome">. But I only got an error and none of the pages would load.

I know nothing about StartingNodeOffset as my knowledge of .net doesn't go beyond your book.
Terry

Reply With Quote
  #6 (permalink)  
Old April 9th, 2008, 03:47 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

What error did you get? You shouldn't get one, as far as I know...

Also, make sure you are referencing the right ID; yours may be named differently....

Imar



---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #7 (permalink)  
Old April 9th, 2008, 04:03 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried all ID references in case I was missing something. It only applies to when I keep the Web.config file to <page theme="Monochrome">

I haven't been able to try it when I change the Web.config to <pages styleSheetTheme="Monochrome"> because I just get the following error on all pages:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 22: End If
Line 23: End If
Line 24: Select Case Page.Theme.ToLower()
Line 25: Case "darkgrey"
Line 26: Menu1.Visible = False


Source File: D:\Web\NET Websites\Visual Studio 2008\WROX\BegASPNET\Site\MasterPages\MasterPage.ma ster.vb Line: 24

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   MasterPage.Page_Load(Object sender, EventArgs e) in D:\Web\NET Websites\Visual Studio 2008\WROX\BegASPNET\Site\MasterPages\MasterPage.ma ster.vb:24
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Control.LoadRecursive() +131
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436




Reply With Quote
  #8 (permalink)  
Old April 9th, 2008, 04:10 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just in case, there is the code for MasterPage.master.vb:

Partial Class MasterPage
    Inherits System.Web.UI.MasterPage

    Protected Sub lstPreferredTheme_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstPreferredTheme.SelectedIndexChanged
        Dim preferredTheme As HttpCookie = New HttpCookie("PreferredTheme")
        preferredTheme.Expires = DateTime.Now.AddMonths(3)
        preferredTheme.Value = lstPreferredTheme.SelectedValue
        Response.Cookies.Add(preferredTheme)
        Response.Redirect(Request.Url.ToString())
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim selectedTheme As String = Page.Theme
            Dim preferredTheme As HttpCookie = Request.Cookies.Get("PreferredTheme")
            If preferredTheme IsNot Nothing Then
                selectedTheme = preferredTheme.Value
            End If
            If lstPreferredTheme.Items.FindByValue(selectedTheme) IsNot Nothing Then
                lstPreferredTheme.Items.FindByValue(selectedTheme) .Selected = True
            End If
        End If
        Select Case Page.Theme.ToLower()
            Case "darkgrey"
                Menu1.Visible = False
                TreeView1.Visible = True
            Case Else
                Menu1.Visible = True
                TreeView1.Visible = False
        End Select
    End Sub
End Class

Reply With Quote
  #9 (permalink)  
Old April 9th, 2008, 04:19 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

There is no Theme, so Page.Theme.ToLower results in an error. Try wrapping it a check with String.IsNullOrEmpty.

If Not String.IsNullOrEmpty(Page.Theme) Then
    Select Case Page.Theme.ToLower()
    ....
End If


IMO, you shouldn't "try all ID references", but you should search for the one you need... ;) The HTML source in the page tells you the exact ID you need ....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #10 (permalink)  
Old April 9th, 2008, 06:14 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I orginally used the ID I though would work. When it failed, I tried the others one at a time, but they all failed.

Back to the <page theme="Monochrome"> verses <pages styleSheetTheme="Monochrome">. When using <pages styleSheetTheme="Monochrome">, I get the error mentioned. I didn't expect the code behind needed to be changed since you didn't mention it in the book.

So we are talking about two different issues now. Just so I can keep mind from getting so confused, we are just trying to settle the issue of using <pages styleSheetTheme="Monochrome"> right now correct?

I changed the code as you suggested:

        If Not String.IsNullOrEmpty(Page.Theme) Then 'added
            Select Case Page.Theme.ToLower()
                Case "darkgrey"
                    Menu1.Visible = False
                    TreeView1.Visible = True
                Case Else
                    Menu1.Visible = True
                    TreeView1.Visible = False
            End Select
        End If 'added
    End Sub

And use <pages styleSheetTheme="Monochrome"> in the web.config file, all the pages in the monochrome theme show the HOME link twice, and in the DarkGrey theme, it shows both themes.

So how do I properly used <pages styleSheetTheme="Monochrome"> as stated in your book? I must be missing something.





Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu Navigation behind Control jwiedmier BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 March 19th, 2008 10:54 AM
Easiest/Recommended Navigation Menu Control/Soluti andhuang ASP.NET 2.0 Professional 0 February 7th, 2007 04:13 PM
Chapter 3 Menu Control ybai BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 June 30th, 2006 02:38 AM
How do I get a menu/navigation look like this? R/O LuxeGirl Classic ASP Basics 4 January 22nd, 2005 08:04 PM
pop up menu on navigation bar joshil Dreamweaver (all versions) 0 May 16th, 2004 07:53 AM



All times are GMT -4. The time now is 05:16 AM.


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