News

Laurent Kempé MVP

Contact

My status

View Laurent Kempé's profile on LinkedIn
XING


Xbox 360



Map

Locations of visitors to this page

.NET Dudes

Family

French .NET Dudes

Friends

Links

Tech Head Brothers

First experience with CSS friendly control adapters beta

I had the chance to realize that CSS friendly control adapters beta from the ASP.NET Team was online for a short time and downloaded it, so I had the pleasure to experience it a bit this evening.

By the way I recommend the reading of the White Paper, that is well written.

So my first idea was to integrate the Menu on Tech Head Brothers. IMHO this new menu is far better than the one delivered with ASP.NET because it uses a pure CSS approach.

After copying the set of needed files to my project, I was able to start changing all the CSS to meet my needs. I did not faced any real issue to change the whole thing, but then I realized that I missed the possibility to know the selected item of my menu. I started to look at the code and in 2 minutes it was changed. Nice.

So I render this:

<div class="THBMenu">
 <div class="AspNet-Menu-Horizontal">
  <ul class="AspNet-Menu">
   <li class="AspNet-Menu-Leaf">
    <a href="/Website/Default.aspx" class="AspNet-Menu-Link">
     Accueil
    </a>
   </li>
   <li class="AspNet-Menu-Leaf">
    <a href="/Website/Articles.aspx" class="AspNet-Menu-Link">
     Articles
    </a>
   </li>
   <li class="AspNet-Menu-Leaf">
    <a href="/Website/Astuces.aspx" class="AspNet-Menu-Link-Selected">
     Astuces
    </a>
   </li>

To achieve this I modified the method BuildItem in the file MenuAdapter.cs like this:

if (item != Control.SelectedItem)
    writer.WriteAttribute("class", "AspNet-Menu-Link");
else
    writer.WriteAttribute("class", "AspNet-Menu-Link-Selected");

And then I added the new thing in the CSS, MenuExample.css:

.THBMenu ul.AspNet-Menu li.AspNet-Menu-Leaf a.AspNet-Menu-Link-Selected
{
    color: #1A2633;
    background: url(../../PersistantImage.ashx?theme=Default&file=Rounded.gif) no-repeat bottom center;
}

For such a result:

[ Currently Playing : Because I Want You - Placebo - Meds (03:22) ]

Comments

EROL said:

Passionnant, car cela s'applique à MOSS, il faudra en parler EROL
# April 29, 2006 2:12 AM

Adrian Tanase said:

I suppose you don't know that you can specify <a href="http://www.google.com/search?hl=en&lr=&q=multiple+css+classes&btnG=Search">multiple css classes</a> for an element. Given the example above, a better way would be to write the class as
<pre>writer.WriteAttribute("class", "AspNet-Menu-Link Selected");</pre>
(note the space)

and only add the selected effect to that rule instead of duplicating the whole code.
# May 3, 2006 2:30 AM

Adrian Tanase said:

PS: sorry for the markup, feel free to edit it
# May 3, 2006 2:30 AM

xdembele said:

hello laurent, could you please tell me how to get an horirontal menu/submenu with asp.net (sitemap, sitemapdatasource, etc.) like the one in http://www.oreillylearning.com/.. i've tried a alot things, but could not get it working. could you help ? thanks in advance
# September 3, 2006 8:43 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)