CodeVerge.Net Beta
Login Idy
Register Password
  Forgot?
   Explore    Item Entry    Profile    Invite   History    Resources   SiteMap  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML




Zone: > newsgroup > asp.net forum > microsoft_downloads.css_friendly_control_adapters Tags:
Item Type: NewsGroup Date Entered: 7/10/2006 7:35:29 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 6 Views: 10 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
7 Items, 1 Pages 1 |< << Go >> >|
kristoffera
Asp.Net User
Custom Menu control - Inline CSS problem7/10/2006 7:35:29 AM

0/0

I've been working on a CSS based menu using the MenuAdapter to override the rendering of the Menu control to ensure that it produces valid HTML. So far the HTML that is sent to the client is correct but when I use runat="server" in the head tag of my page there is some additional inline CSS being rendered in the head section. How do I prevent this from being rendered? Below is an example of the output. The section I'm trying to get rid of is marked in red.
<head>
<title>Title</title>
<style type="text/css">
.ctl00_MainMenu_0 { background-color:white;visibility:hidden;display:none;position:absolute;left:0px;top:0px; }
.ctl00_MainMenu_1 { text-decoration:none; }
.ctl00_MainMenu_2 { }
</style>

</head>

....

<div id="MainMenu">
<ul class="Menu-Root">
<li class="Menu-Leaf"><a href="/Default.aspx" class="Menu-Link Link-Selected"><span>Home</span></a></li>
<li class="Menu-Leaf"><a href="/About.aspx" class="Menu-Link"><span>About</span></a></li>
<li class="Menu-Leaf"><a href="/Contact.aspx" class="Menu-Link"><span>Contact</span></a></li>
</ul>
</div>
As you can see the .ctl00_MainMenu_* classes are unused and should therefore be removed.

TIA / Kristoffer

www.77 dynamite.com
Russ Helfand
Asp.Net User
Re: Custom Menu control - Inline CSS problem7/10/2006 7:27:58 PM

0/0

Thanks for bring this up, Kristoffer.  Wilco Bauwer also noted this problem (in private email to me).  So, it is already on my to-do list.  Unfortunately, these unwanted/unneeded styles aren't easy to get rid of.  They are being gen'ed deep within the framework and are hard to twart.  Still, I'm annoyed by their presence, too, so I'll keep trying to figure out how we might get rid of them when the adapters are in play. Hopefully, I'll figure this out soon!

PS  These styles are used when the control is in its unadapted state.  I believe they are gen'ed by the control when it is in its Init phase.  Since the adapters only kick in during the render phase the unwanted styles are a little hard to purge.


Russ Helfand
Groovybits.com
FogJuice
Asp.Net User
Re: Custom Menu control - Inline CSS problem7/18/2006 1:51:44 PM

0/0

It appears the Menu control is calling Page.Header.Stylesheet.CreateStyleRule() inside of it's OnPreRender() method overload.

The MenuAdapter has an overideable method for OnPreRender, but if you do override it and forget to (or intentionally leave out) call base.OnPreRender, the menu is NOT rendered at all.

My guess is that because a supertype (BaseDataBoundControl?) is calling DataBind() on the control to get it to populate the menu items.

You could "fake" this behavior with the following overload in your MenuAdapter derived class.

 

protected override void OnPreRender(EventArgs e)
{
    Control.DataBind();
    // Do not call the base class implementation.
    // base.OnPreRender(e);
}

 

This will skip registering the stylesheet declarations, but it might also have other effects.  I'm not sure what else is going on in the Menu.OnPreRender overload.

 

 

FogJuice
Asp.Net User
Re: Custom Menu control - Inline CSS problem7/18/2006 2:14:50 PM

0/0

FogJuice:

This will skip registering the stylesheet declarations, but it might also have other effects.  I'm not sure what else is going on in the Menu.OnPreRender overload.

I meant to add that it also registers client side script in addition to stylesheet declarations in the OnPreRender method of the Menu server control.

If you are registering your own styles and scripts, this might not be a problem.

The one caveat I've noticed is that you have to call DataBind on the Control reference (as shown above) or the menu items are never rendered.

 

Russ Helfand
Asp.Net User
Re: Custom Menu control - Inline CSS problem7/18/2006 3:55:28 PM

0/0

I'm going to ping some of the folks on the team to see if we can figure out how to override OnPreRender safely.  I think this line of investigation (i.e., eliminating the unwanted styles by taking over OnPreRender from the adapter) is a fruitful path forward.  Nice work, FogJuice.
Russ Helfand
Groovybits.com
kristoffera
Asp.Net User
Re: Custom Menu control - Inline CSS problem8/1/2006 8:04:15 PM

0/0

Thanks for posting guys! Any news on the subject Russ?

All the best // Kristoffer


www.77 dynamite.com
Russ Helfand
Asp.Net User
Re: Custom Menu control - Inline CSS problem8/1/2006 8:37:10 PM

0/0

I had a lively email discussion within the team.  Program Managers, Architects and Devs chipped in.  Betrand Le Roy dug through all the code and determined that the Menu case it appears that you can get away with the proposed solution (above).  However, the same simple solution is probably not viable for all controls (e.g., TreeView, etc.) since the prerender processing is control specific and may be more involved in some of those other cases.

So, you might ask, what should we do? Personally, I think this is one of those times when it is better to err on the side of caution. I think it's important that we balance what we are trying to gain (the elimination of a relatively small number of useless styles embedded in the HEAD) with what we stand to lose (stability, maybe).


Russ Helfand
Groovybits.com
7 Items, 1 Pages 1 |< << Go >> >|



Search This Site:


Other Resources:

Menu and Inline CSS - newsgroup.asp-net-forum.general_asp-net ... Menu and Inline CSS, > ROOT > NEWSGROUP > Asp.Net Forum > general_asp.net. ... Custom Menu control - Inline CSS problem - ASP.NET Forums : I've been working on ...
CSS Adapter Menu Control Problem - microsoft_downloads ... CSS Adapter Menu Control Problem, > ROOT > NEWSGROUP > Asp.Net Forum > ... CSS Friendly Control Adapters ... Custom Menu control - Inline CSS problem by kristoffera ...
Custom Menu control - Inline CSS problem - ASP.NET Forums Custom Menu control - Inline CSS problem. Last post 08-01-2008 11:07 AM by cnobles. ... Re: Custom Menu control - Inline CSS problem. 07-18-2006, 10:14 AM ...
CSS Friendly Control Adapters ... disabled: any way to make CSSFriendly menus work? ... Custom Menu control - Inline CSS problem. Menu Adapter - Adapter Enabled not working as expected. ...
ASP.NET Control Gallery - EO.Web Menu Inline CSS style editor: Edit and preview CSS style at design time; ... Any problems I encountered were nuances with css classes that the support team ...
White Paper: ASP.NET 2.0 CSS Friendly Control Adapters 1.0 ... might solve certain problems where you've employed custom controls in the past. ... cause the control to generate additional markup, inline or embedded CSS. ...
Horizontal CSS Menus || CSS Menu Builder ... menu templates that lets you have full control over the ... Custom Menu Work. Can't find the menu you want? Having problems installing one of our menus? ...
Yahoo! UI Library: Menu ... "CSS skins": One of the files listed above contains a CSS "skin" for the Menu Control. ... this problem the "overflow" property of a Menu instance's shadow ...
Coding4Fun : Who Is Looking: Building a Custom ASP.NET Control that ... Selecting this menu item will open a dialog box that enables you to browse to an ... Our control is going to inject Javascript and CSS into its containing page. ...
CSS and HTML [Archive] - Ultimate Web Site Drop Down Menu Forum Html Volume Control. Absolute Positioned Blocks Contained ... display: inline problem. Optimum way of writing this code? some problems on ie. Frames help ...
CodeProject: A Resource Server Handler Class For Custom Controls. Free ... Custom Controls. HTML / CSS. Internet / Network. ISAPI. Site & Server Management. Session State ... However, it may complicate distribution of the custom control. ...
Custom CSS Signatures in Mail (UPDATED) " All Forces ... clients) but the use of DIVs and CSS allows you a lot more control. ... Other problem : if your styles aren't "inline", they will be discared by various ...



 
All Times Are GMT