Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 11th, 2011, 03:24 PM
Authorized User
 
Join Date: Jul 2009
Location: Haslemere, Surrey, England
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default problem with StaticSelectedStyle in a menu

Hi,

I am having a problem getting StaticSelectedStyle to work with my menu. The StaticMenuItemStyle and the StaticHoverStyle work just fine (ie changes in the style are reflected in the displayed page) but the StaticSelectedStyle seems to be ignored :(. Doesn't matter what element I change (font, color, background-color) nothing is changed??

I have a Master page and then two master pages nested below that.
i.e Master1 and then MasterBusiness and MasterHome use Master1 as their Master. Both behave in the same way.

Help appreciated!

I have the following menu in the masterbusiness page (and a similar one in another masterhome page):
Code:
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" align="center" 
                StaticEnableDefaultPopOutImage="false" MaximumDynamicDisplayLevels="3" 
           Width="362px" >
            
            <StaticMenuItemStyle CssClass="StaticMenuItemStyle" />
            <StaticSelectedStyle   CssClass="StaticSelectedStyle" />
            <StaticHoverStyle cssclass="StaticHoverStyle"/>
            <DynamicMenuItemStyle CssClass="DynamicMenuItemStyle" />
            <DynamicHoverStyle cssclass="DynamicHoverStyle"/>
            <Items>
                <asp:MenuItem NavigateUrl="~/Home-IT-Computer-Support.aspx" 
                  Text="Home Computing" Value="Home Computing"></asp:MenuItem>
                <asp:MenuItem NavigateUrl="~/Business-IT-Computer-Support.aspx" 
                Text="Business Computing" Value="Business"></asp:MenuItem>
              <asp:MenuItem NavigateUrl="~/AntiVirus-Business.aspx" Text="AntiVirus Solutions" Value="AntiVirus Solutions"></asp:MenuItem>
              <asp:MenuItem NavigateUrl="~/Backup-and-Disaster-Recovery.aspx" 
                Text="Backup / Disaster Recovery" Value="Backup"></asp:MenuItem>
              <asp:MenuItem NavigateUrl="~/Voip.aspx" Text="VoIP Systems" Value="VoIP Systems"></asp:MenuItem>
              <asp:MenuItem NavigateUrl="~/contact.aspx" Text="Contact Us " Value="Contact Us"></asp:MenuItem>
            </Items>
         </asp:Menu>
My css file contains:
Code:
.StaticMenuItemStyle, .StaticMenuItemStyle:visited
{
  padding-left: 5px;
  padding-top: 2px;
  padding-right: 5px;
  padding-bottom: 2px;
  font-family: Verdana;
  color: #c1272d;
  text-align: center;
  height: 30px;
  width: 150px;
  vertical-align: middle;
  white-space: pre-wrap;
}
.StaticSelectedStyle
{  
padding-left: 5px;
padding-top: 2px;
padding-right: 5px;
padding-bottom: 2px;
font-family: Verdana;
color: green;
text-align: center;
height:30px;
width: 150px;
vertical-align: middle;
white-space: pre-wrap;
}

.StaticHoverStyle, .StaticHoverStyle:visited
{  
padding-left: 5px;
padding-top: 2px;
padding-right: 5px;
padding-bottom: 2px;
font-family: Verdana;
color: black;
text-align: center;
height:30px;
width: 150px;
vertical-align: middle;
white-space: pre-wrap;
}
__________________
Geoff Baldwin
  #2 (permalink)  
Old April 11th, 2011, 03:33 PM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Do you see the StaticSelectedStyle class end up in the HTML? In other words, is it a Menu issue or a CSS issue?

Is there a live page we can look at?

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!
  #3 (permalink)  
Old April 11th, 2011, 03:53 PM
Authorized User
 
Join Date: Jul 2009
Location: Haslemere, Surrey, England
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default

Thanks for the Interest Imar.

The site I am building is at http://website1.beaufortnetworks.com (not yet live as I still have a few things to work on!!)

My current site uses a similar menu and CSS (only one master page) and it works Ok there : www.beaufortnetworks.com

Geoff
__________________
Geoff Baldwin
  #4 (permalink)  
Old April 11th, 2011, 04:30 PM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I don't see the SelectedStyle appear anywhere in the source, so it seems a Menu / setup issue instead of an CSS issue.

Try bringing down the the problem to just a few pages with a simple sitemap and see if that sheds any light.

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!
  #5 (permalink)  
Old April 11th, 2011, 05:54 PM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I did some digging and it seems the Selected property is not set when using static items. Not sure why that is though. It works fine with a Sitemap file though.

For more information: http://forums.asp.net/t/1162642.aspx/1

http://www.google.com/#sclient=psy&h...ems+collection

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!
  #6 (permalink)  
Old April 11th, 2011, 06:01 PM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You may also want to check out this article: http://www.maconstateit.net/tutorial...pnet12-02.aspx, especially the section "Selected Styles and Master Pages".

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!
  #7 (permalink)  
Old April 11th, 2011, 06:29 PM
Authorized User
 
Join Date: Jul 2009
Location: Haslemere, Surrey, England
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default

Thanks for the input Inmar

My Live site uses a sitemap so I am testing with a sitemap but have hit another problem (unrelated in itself).
I created a sitemap called Business.sitemap and placed it in the root of my site.
My sitemap datasource looks like this:
Code:
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"  SiteMapProvider="~/Business.sitemap" ShowStartingNode="False" />
If I use ctlF5 to test and click on a menu item that takes me to pages using the Business master I get an error "The SiteMapProvider '~/Business.sitemap' cannot be found"
I have also tried ./Business.sitemap and ../Business.sitemap to no avail

I think this is related to another issue I am experiencing but I haven't solved yet which is that in the statement:
Code:
<img style="height:199px" alt="Beaufort Networks Logo" src="./images/BusinessIn.jpg" align="right" />
The image source is flagged as an error in Visual Studio and does not display in the design view but displays correctly on the site. (the only way I could get it to display -- and I have the same issues with other images.)

This code is in the business master page using the master master page and they are in a folder master pages in the root directory.
The images are in a folder called images also in the root of the directory.

Using ../images/businessin.jpg gets rid of the error in Visual Studio and the image displays in the design viewbut does not display when the site is run using CTL F5 ??????
using ~/images/businessin.jpg does not show an error but the images does not show either in the design viewor on the site when tested.

My site directory/folder structure seems to be not working as I would expect.

Well it's 11:25pm now and I'm tired so I will be visiting this again tomorrow. If you have any more pointers I'd appreciate them :)
__________________
Geoff Baldwin
  #8 (permalink)  
Old April 12th, 2011, 02:38 AM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Geoff,

Take a look here: Different items in WebSiteMap and Menu and at the link I posted in that thread.

You don't assign a site map file to the SiteMapProvider property, but you assign a site map provider that has been configured in web.config. The provider then in turn has a reference to the sitemap file.

With regard to the image issues: check out Chapter 7. It deals with this topic in detail.

Hope this helps,

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!
  #9 (permalink)  
Old April 12th, 2011, 06:49 PM
Authorized User
 
Join Date: Jul 2009
Location: Haslemere, Surrey, England
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default

Hi Imar
I appreciate your help on this.

I have read the thread you pointed me at and I now have the following in my web.config:
Code:
<siteMap defaultProvider="XmlSiteMapProvider">
      <providers>
        <add
          name="BusinessMenu"
          type="System.Web.XmlSiteMapProvider"
          siteMapFile="~/Sitemaps/business.sitemap" />
        <add
          name="HomeMenu"
          type="System.Web.XmlSiteMapProvider"
          siteMapFile="~/Sitemaps/home.sitemap" />
        <add
        name="DefaultMenu"
        type="System.Web.XmlSiteMapProvider"
        siteMapFile="~/Sitemaps/Default.sitemap" />
      </providers>
    </siteMap>
  </system.web>
And this in my master page :
Code:
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"  SiteMapProvider="BusinessMenu" ShowStartingNode="False" />
I also tried XmlSiteMapProvider instead of Business.sitemap

I get Parser Error Message: The provider 'XmlSiteMapProvider' specified for the defaultProvider does not exist in the providers collection when I try and access a page using the Business.master page.

You can see that I am very much struggling here and I'm probably missing what to you is a basic such as defining/registering XmlSiteMapProvider...but I am not a regular web developer and am revisiting this project after a year or two and have no idea where to to do this or why.
__________________
Geoff Baldwin
  #10 (permalink)  
Old April 13th, 2011, 02:46 AM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Geoff,

When you register a sitemap provider in web.config, you link a name (like BusinessMenu) to a type (such as System.Web.XmlSiteMapProvider, but you could also create your own).

You then need to link to this name when specifying the default (in the web.config file), or an explicit provider (in a SiteMapDataSource element). So, I think the following should work:

Code:
 
<siteMap defaultProvider="DefaultMenu">
  <providers>
 <add
   name="BusinessMenu"
   type="System.Web.XmlSiteMapProvider"
   siteMapFile="~/Sitemaps/business.sitemap" />
 <add
   name="HomeMenu"
   type="System.Web.XmlSiteMapProvider"
   siteMapFile="~/Sitemaps/home.sitemap" />
 <add
 name="DefaultMenu"
 type="System.Web.XmlSiteMapProvider"
 siteMapFile="~/Sitemaps/Default.sitemap" />
  </providers>
</siteMap>
And then in your code, you should refer to the named procider, like this:

Code:
 
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"  SiteMapProvider="BusinessMenu" ShowStartingNode="False" />
With this code, ASP.NET finds the configured provider (BusinessMenu) and then instantiates its underlying type (System.Web.XmlSiteMapProvider). This type then knows how to read the XML configuration code (such as the filename), reads the sitemap file and performs its magic.

Hope this helps,

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:
SouthendSupporter (April 13th, 2011)
 


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 problem barakros BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 February 18th, 2010 04:41 PM
Problem with Menu Item nelly78 BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 0 January 29th, 2010 01:14 PM
problem with my menu in ie6 johnficca CSS Cascading Style Sheets 1 May 6th, 2007 07:41 PM
CSS Menu problem twc02 CSS Cascading Style Sheets 24 March 11th, 2005 11:01 AM
menu positioning problem isheikh HTML Code Clinic 27 June 5th, 2004 10:52 AM



All times are GMT -4. The time now is 11:42 AM.


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