Connecting Tech Pros Worldwide Forums | Help | Site Map

How to do onmouseover/onmouseout events on asp.net button

Rob Roberts
Guest
 
Posts: n/a
#1: Jan 27 '06
I'm using .NET 2.0 and C# on a web site, and I'm trying to use the
onmouseover and onmouseout events to do a rollover effect on an asp.net
button. I've tried manually adding the events to the asp:button tag. The
events I added look like this:

onmouseover="this.className='btnNormal'"
onmouseout="this.className='btnOver'"

This works fine, with the rollover appearing as it should. But when I build
the project in VS2005, I get a validation warning saying "Validation
(ASP.Net): Attribute 'onmouseover' is not a valid attribute of element
'Button', and another one saying the same thing about onmouseout attribute.

So after searching through newsgroup archives, I found recommendations that
this be done by adding the attributes in the Page_Load event, like this:

MyButton.Attributes.Add("onmouseover", "this.className='btnNormal'");
MyButton.Attributes.Add("onmouseout", "this.className='btnOver'");

But I can't get this to work. It compiles just fine, but the events aren't
included in the HTML sent to the browser, and so of course the rollover
effect doesn't work.

What is the best way to handle rollovers like this?

Thanks in advance,
--Rob Roberts



Fao, Sean
Guest
 
Posts: n/a
#2: Jan 27 '06

re: How to do onmouseover/onmouseout events on asp.net button


Rob Roberts wrote:[color=blue]
> I'm using .NET 2.0 and C# on a web site, and I'm trying to use the
> onmouseover and onmouseout events to do a rollover effect on an asp.net
> button.[/color]

This is the job of JavaScript and/or CSS. Posting back to a server for
these events would put excessive load on your server. Not to mention
that it would be incredibly slow.

HTH,

--
Sean
Rob Roberts
Guest
 
Posts: n/a
#3: Jan 28 '06

re: How to do onmouseover/onmouseout events on asp.net button


"Fao, Sean" <enceladus311@yahoo.comI-WANT-NO-SPAM> wrote in message
news:ufIqA24IGHA.528@TK2MSFTNGP12.phx.gbl...[color=blue]
> Rob Roberts wrote:[color=green]
>> I'm using .NET 2.0 and C# on a web site, and I'm trying to use the
>> onmouseover and onmouseout events to do a rollover effect on an asp.net
>> button.[/color]
>
> This is the job of JavaScript and/or CSS. Posting back to a server for
> these events would put excessive load on your server. Not to mention that
> it would be incredibly slow.[/color]

Well, yes, but that's what I'm trying to do. That's why I first tried
adding these event handlers to the button declaration in the aspx file:

onmouseover="this.className='btnNormal'"
onmouseout="this.className='btnOver'"

And while that works just fine in giving the desired rollover effect
(without a postback to the server), VS2005 complains about it, saying that
"Attribute 'onmouseover' is not a valid attribute of element 'Button'".

--Rob Roberts


Nathan Sokalski
Guest
 
Posts: n/a
#4: Jan 28 '06

re: How to do onmouseover/onmouseout events on asp.net button


I think that you are simply using an invalid attribute. When using
Javascript to change the CSS Class, you use the 'class' attribute.
Therefore, your code should be:

MyButton.Attributes.Add("onmouseover", "this.class='btnNormal'");
MyButton.Attributes.Add("onmouseout", "this.class='btnOver'");

Hopefully this will solve your problem. Good Luck!
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

"Rob Roberts" <robrRemoveThis@AndThisToo.pcisys.net> wrote in message
news:%23q1yh$3IGHA.528@TK2MSFTNGP12.phx.gbl...[color=blue]
> I'm using .NET 2.0 and C# on a web site, and I'm trying to use the
> onmouseover and onmouseout events to do a rollover effect on an asp.net
> button. I've tried manually adding the events to the asp:button tag. The
> events I added look like this:
>
> onmouseover="this.className='btnNormal'"
> onmouseout="this.className='btnOver'"
>
> This works fine, with the rollover appearing as it should. But when I
> build the project in VS2005, I get a validation warning saying "Validation
> (ASP.Net): Attribute 'onmouseover' is not a valid attribute of element
> 'Button', and another one saying the same thing about onmouseout
> attribute.
>
> So after searching through newsgroup archives, I found recommendations
> that this be done by adding the attributes in the Page_Load event, like
> this:
>
> MyButton.Attributes.Add("onmouseover", "this.className='btnNormal'");
> MyButton.Attributes.Add("onmouseout", "this.className='btnOver'");
>
> But I can't get this to work. It compiles just fine, but the events
> aren't included in the HTML sent to the browser, and so of course the
> rollover effect doesn't work.
>
> What is the best way to handle rollovers like this?
>
> Thanks in advance,
> --Rob Roberts
>
>[/color]


Closed Thread