Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Adding MouseOver to imageButtons

Author  Topic 

webninja
Starting Member

6 Posts

Posted - 2003-11-17 : 10:10:19
Is there a way to add javascript mouseover(image swaps) to the <asp:ImageButton> Server control?

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-11-17 : 16:57:37
Doesn't look like you can natively.
But, you could create a control that inherits ImageButton. Then override the Render method and add it there.



Damian
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2003-11-17 : 18:23:59
I'm pretty sure someone has done this at asp.net. You might want to check the Control Gallery there to find one.

If you have the javascript that handles the rollovers, you should be able to add those function calls into the imagebuttons OnClientClick() event.

Take a look at this forum post:
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=388364

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2003-11-17 : 18:25:21
Doh, I think i misread your question.
You'll need to do the Attributes.Add method mentioned on that page to make your rollovers work. The OnClientClick() event will not help you.

Michael



<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-11-17 : 18:28:23
Of course!

I AM slow today.


Damian
Go to Top of Page

Granick
Starting Member

46 Posts

Posted - 2003-11-17 : 19:58:09
I understand the reasoning why you have to use the Attribute.Add method, but it is one of the things that has always seemed to be a pain to me. They did so much to try and make our lives easier, so that the Designer can work on a page and I can work on the code, with less problems, and then to make it so that you have to put stuff like this in the code behind just seems backwards.

Course, then there is the fact that in some cases, you can just throw the event on there, ignoring the fact that .Net doesn't like it, and it will work fine. This is only really a pain, because our designer has EVERYTHING with a rollover. :)

Shannon
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2003-11-17 : 20:03:46
Granik,
For you Merkin's orignal suggestion is the way to go then. It'd probably take all of 30 minutes or so to create this new control, and then you could allow your designer to control all the rollover stuff, and you get all that Attribute.Add() stuff out of your code.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>

Edit: Opps had Attribute.Ass() instead of Attribute.Add(), but it's just about the same thing anyway eh?
Go to Top of Page

webninja
Starting Member

6 Posts

Posted - 2003-11-18 : 08:26:49
After searching the microsoft site for quite a while I stumbled across this solution. I tried the ones suggested above but they didn't work. This seems to work pretty well. Thanks for all the help guys.

<asp:ImageButton
ID="IBPartners"
onmouseover="this.src='/images/homepage/n_btn_partner-over.gif';"
onmouseout="this.src='/images/homepage/n_btn_partner.gif';"
imageURL="/images/homepage/n_btn_partner.gif"
width='79'
height='18'
OnClick="PartnerSites_Click"
Runat="Server" />
Go to Top of Page
   

- Advertisement -