The Brand New Menu.IncludeStyleBlock Property

Along with the popular new features of ASP.NET 4, some uncommon features have been added as well. One of them is the Menu control which has gone through some changes, good ones.

One of the changes to the control is the new IncludeStyleBlock property. This is a boolean value which indicates whether the control adds its CSS to the page. “Oh well…” you might say, but stop and rethink it – until now, when you used the Menu control you always had the CSS added to the page, whether you liked it or not. For example, the following is a CSS block which is added to the page when a menu with a simple format exists within it:

<style type="text/css">

/* <![CDATA[ */

#Menu1 { background-color:#FFFBD6; }

#Menu1 img.icon { border-style:none;vertical-align:middle; }

#Menu1 img.separator { border-style:none;display:block; }

#Menu1 ul { list-style:none;margin:0;padding:0;width:auto; }

#Menu1 ul.dynamic { background-color:#FFFBD6;z-index:1;margin-left:2px; }

#Menu1 a { color:#990000;font-family:Verdana;font-size:0.8em;text-decoration:none;white-space:nowrap;display:block; }

#Menu1 a.static { padding:2px 5px 2px 5px;text-decoration:none; }

#Menu1 a.popout { background-image:url("/WebResource.axd?d=HGk9oAfq1wga-jOpKNLje9tJtu3SgIdPSvUFv2UWscw1&t=634045276053254044");background-repeat:no-repeat;background-position:right center;padding-right:14px; }

#Menu1 a.dynamic { padding:2px 5px 2px 5px;text-decoration:none; }

#Menu1 a.static.selected { background-color:#FFCC66;text-decoration:none; }

#Menu1 a.dynamic.selected { background-color:#FFCC66;text-decoration:none; }

#Menu1 a.static.highlighted { color:White;background-color:#990000; }

#Menu1 a.dynamic.highlighted { color:White;background-color:#990000; }

/* ]]> */

</style>

This sucks. It isn’t cached by the browser, it increases your page size and it might become even bigger if you have some more complex styles. If this irritates you as it irritates me, the IncludeStyleBlock property is for you. Just set it to false and the above CSS disappears from the page.

However… by setting the IncludeStyleBlock property to false you remove the style completely and we don’t want that.
There are two possible solutions to this issue:

  • Copy the generated CSS to a CSS file (before you set the IncludeStyleBlock to false) and add a link to the file on the page - <link href="Styles/style.css" rel="stylesheet" type="text/css" />
  • Create a custom CSS class for the menu and set its name to the menu’s CssClass property.

In conclusion, the IncludeStyleBlock is a really nice enhancement to the handy Menu control. Notice that this is not the only change to the Menu control in ASP.NET 4, it also uses UL and LI elements instead of tables!
To read more about the changes in the Menu control in ASP.NET 4, look here.

And I say – hallelujah!

All the best,
Shay.

kick it on DotNetKicks.com Shout it




Comments

March 22. 2010 10:45 PM

trackback

ASP.NET 4: The Brand New Menu.IncludeStyleBlock Property

Thank you for submitting this cool story - Trackback from DotNetShoutout

DotNetShoutout

March 22. 2010 10:45 PM

trackback

ASP.NET 4: The Brand New Menu.IncludeStyleBlock Property

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com

March 24. 2010 05:36 AM

trackback

ASP.NET 4: The Brand New Menu.IncludeStyleBlock Property

Thank you for submitting this cool story - Trackback from iAwaaz-News-by-People

iAwaaz-News-by-People

November 30. 2010 12:22 AM

PC zusammenstellen

Thanks Shay for posting! Hallelujah! ;)

PC zusammenstellen

January 3. 2011 05:52 PM

Richard

Hey Shay thanks for posting this . I am currently studying ASP at college so every scrap of information helps!  Appreciated.

Richard

January 14. 2011 01:12 AM

Pigroll

Geez, I wonder if I'll ever be able to get a grasp on ASP.NET. God knows I'm trying Smile Thanks for the post!

Pigroll

January 17. 2011 09:36 AM

pingback

Pingback from radanhepzi.storeblogs.com

Satmap Active 10 Plus Review | Radan

radanhepzi.storeblogs.com

March 27. 2011 06:11 PM

pingback

Pingback from hotcelebrity101.wordpress.com

Bobbi Kristina Gets Her Own Reality Show!? + Michelle Obama To Speak At Spelman Commencement | Hot Celebrity Gossip

hotcelebrity101.wordpress.com

June 25. 2011 02:04 PM

pingback

Pingback from stagy.wordpress.com

MenuControl asp.net 4  «  Stagy's Blog

stagy.wordpress.com

March 14. 2013 10:55 AM

massage London

It is a great post to me. I am astonish for this post.I want that will give us more important information.So carry on

massage London

March 16. 2013 11:02 AM

Ms. Coco

Thanks for your exclusive post. I am benefited for this post so thank you.

Ms. Coco

March 19. 2013 08:25 AM

Mr. Mohammed Sami

Very important information are included in this post. I think you will more valuable information add this site,So meany meany thanks, carry on

Mr. Mohammed Sami

March 20. 2013 10:34 AM

Mr. Mohammed Sami

This is a great post to me. I am astonish for this post.I want that will give us more important and useable information.So carry on

Mr. Mohammed Sami

April 1. 2013 03:51 PM

wastestreamconsultants

Thanks for any other great article. Where else may anyone get that kind of info in such a perfect method of writing? I have a presentation subsequent week, and I’m at the search for such info.

wastestreamconsultants

April 2. 2013 02:23 PM

mobile website design toronto

This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! Keep up the good work.

mobile website design toronto

May 11. 2013 07:18 PM

petrol lawn mower

Some of the points you have raised will assist me greatly. I like the way you have structured your site, it is super and very easy to follow. I have bookmarked you and will be back regularly.

petrol lawn mower

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Subscribe Subscribe

That's Me!

Hi! I'm Shay Friedman
I'm Shay Friedman - a Visual C#/IronRuby MVP, a consultant and instructor of .NET technologies, author, speaker and new technologies freak
More about me

Contact Me

> Contact page
> Twitter: @ironshay
> LinkedIn profile

Search

Hosted By

I'm hosting this site on Arvixe and I'm very happy with it.
If you're looking for ASP.NET hosting, I highly recommend it
(and if you order from this link I also get some beer money!)
Web Hosting