Tuesday, April 1, 2008

Another (more complex) way to hover in ASP in IE6

IE6 doesn't have support for pseudo-class hovering (only anchor hovering). I was working on a piece of code today and we wanted to get a bunch of labels to change background when hovered over. We only support IE6 SP2. This was a fun day, I must say. What I ended up doing was creating a div that held all the labels, gave it an ID and runat="server".

[div ID="someDiv" runat="server"]

I stuck all the labels inside this div. Then, I did a foreach loop to grab all the controls.

foreach (Control ctrl in someDiv.Controls)
if (ctrl.GetType() == typeof(Label))
ctrl.Attributes.Add("onmouseover", "this.style.backgroundColor = 'Grey'");
ctrl.Attributes.Add("onmouseout", "this.style.backgroundColor="White"');

The one I did was _much_ more complicated than this because I had to highlight multiple labels at once with one mouseover (as well as deal with some weird variable names). Much deeper looping, but once you get it going, it is just finding the right way to loop through it. In my testing, this did _not_ work in Firefox. Since I don't get paid to work on it for Firefox, I won't delve too deep into it. Though Firefox supports pseudo-class hovering, so that isn't really a problem.

No comments:

Post a Comment