|
|
 |
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |
|

April 8th, 2008, 11:16 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

April 8th, 2008, 05:11 PM
|
 |
Wrox Author
Points: 33,563, Level: 80 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,231
Thanks: 7
Thanked 203 Times in 201 Posts
|
|
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.
|

April 8th, 2008, 10:16 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 9th, 2008, 05:22 AM
|
 |
Wrox Author
Points: 33,563, Level: 80 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,231
Thanks: 7
Thanked 203 Times in 201 Posts
|
|
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.
|

April 9th, 2008, 04:08 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 9th, 2008, 04:47 PM
|
 |
Wrox Author
Points: 33,563, Level: 80 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,231
Thanks: 7
Thanked 203 Times in 201 Posts
|
|
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.
|

April 9th, 2008, 05:03 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 9th, 2008, 05:10 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 9th, 2008, 05:19 PM
|
 |
Wrox Author
Points: 33,563, Level: 80 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,231
Thanks: 7
Thanked 203 Times in 201 Posts
|
|
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.
|

April 9th, 2008, 07:14 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |