473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
Jan 27 '06 #1
3 7413
Rob Roberts wrote:
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.


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
Jan 27 '06 #2
"Fao, Sean" <en**********@yahoo.comI-WANT-NO-SPAM> wrote in message
news:uf*************@TK2MSFTNGP12.phx.gbl...
Rob Roberts wrote:
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.


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.


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
Jan 28 '06 #3
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
nj********@hotmail.com
http://www.nathansokalski.com/

"Rob Roberts" <ro************@AndThisToo.pcisys.net> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
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

Jan 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: christian9997 | last post by:
Hi I was trying to create a page where a SubMenu would appear when the user moved the mouse over an item of a Menu (= Table Cell <TD>). Unfortunately there seems to be a problem; the onMouseOver...
12
by: Epetruk | last post by:
Hi all, I want a page where the contents of a table cell are replaced with an image when the mouse moves over the cell, and the text is restored when the mouse moves out. Here's the html for the...
2
by: Bendik Engebretsen | last post by:
Hi, ASP.NET newbie has just started expermenting with VS.NET 2005 Beta, ASP.NET 2.0 and the 'Personal WEB site' starter kit. I am now trying to create a rollover effect on the buttons. I have...
2
by: MrCode2k | last post by:
Hello, Trying to do: I just want a table that I can scroll and that has fixed headers. Problem: I got it to work but when I added the onmouseover event it didn't work anymore....
1
by: mike.thirlwell | last post by:
Hi there, I've created the following demo to illustrate a problem I've been having with Safari (2.0.3 in my case) firing onmouseout events when the onmouseover event should be being triggered....
0
by: jceddy | last post by:
Hi...I hope I am posting this in an appropriate place...if not, could some direct me to someplace better? Anyway, the problem I have is that I have a page with a table with two rows. The top...
3
by: oopaevah | last post by:
I have written some dom code to create a list of divs, each with it's own id. I want to set the onmouseover and onmouseout events to highlight the div when the mouse is over it. However I cannot...
2
by: Daz | last post by:
Hi everyone. I think my problem is a simple one, but I am completely baffled as to how to pull it off. I have a piece of code like so... document.write( "<img id=\"slideshow_toggle\"...
3
by: equazcion | last post by:
Hi, I have an image reference (IMG) in my page that changes depending on the value of a database field. Clicking the image triggers an Ajax call to change the database field (toggles the field...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.