user28584
user28584

Reputation: 1095

How can I stop ASP.NET Menu controls from generating inline html style elements

I have a master page that contains an ASP.NET server side Menu control (System.Web.UI.WebControls.Menu)

I am using the CSSFriendly adapters from here

http://www.asp.net/CSSAdapters/Menu.aspx

and they do make the rendered HTML much cleaner however I am still getting inline styles output into the HEAD element in the HTML like this

<style type="text/css">
    .ctl00_SiteHeader1_TabBar1_Menu1_0 { background-color:white;visibility:hidden;display:none;position:absolute;left:0px;top:0px; }
    .ctl00_SiteHeader1_TabBar1_Menu1_1 { text-decoration:none; }
    .ctl00_SiteHeader1_TabBar1_Menu1_2 {  }
    .ctl00_LeftColumnContent_LeftHandNavigator1_Menu1_0 { text-decoration:none; }

</style>
</head>

<body>

I thik these styles are being generated by ASP.NET, I don't think I need them as I am using the CSSAdapters so is there any way of stopping them from being generated?

Derek

Upvotes: 5

Views: 2530

Answers (2)

Ignacio Calvo
Ignacio Calvo

Reputation: 834

In .NET Framework 4, ASP.NET menu has a new property, IncludeStyleBlock, that you can set to false to avoid generation of <style> block. However, it still generates a style="float:left" attribute that can only be overridden with a float: none !important in your stylesheet.

Upvotes: 3

Cristian Libardo
Cristian Libardo

Reputation: 9258

The short story is that it isn't easily accomplished. That code is added to the header by the menu during the prerender phase.

A possible workaround might be overriding the menu's onprerender in a custom menu control and don't call base. You could then replace the default menu control with your own using tagMappings.

I'd suggest you stay clear of the menu control if you can.

Upvotes: 1

Related Questions