473,398 Members | 2,404 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,398 software developers and data experts.

Rollover asp.net Button

Hi there,

I would like to handle a "rollover" <asp:Buttonin the code behind with C#
with this kind of code:

Button btn = Page.FindControl("Button" + numWidget) as
Button;
btn.Attributes["onmouseover"] = "document.all." +
btn.ClientID + ".src = '/Images/blue.gif'";

This code works for ImageButton...but not for Button (it does nothing).

My goal is to change the background image.

Best regards

Sep 30 '08 #1
3 2714
It doesn't work for the Button control because the html input tag doesn't
have a src attribute. But can I also ask why you are using a Button control
when you want to assign it a *.gif file? However, if all you are looking to
do is add a rollover feature to the Button that changes the background
color, you may want to take a look at the AddRolloverBackgroundColor
function I have written that is available on my website at:

http://www.nathansokalski.com/code/RolloversClass.aspx

Here is the simple code for the function if you want it separately from the
other rollover functions I have written:

Public Shared Sub AddRolloverBackgroundColor(ByVal ctrl As
System.Web.UI.WebControls.WebControl, ByVal rollover As
System.Drawing.Color, ByVal initial As System.Drawing.Color)
'Adds the background color rollover feature to a WebControl
ctrl.BackColor = initial
ctrl.Attributes.Add("onmouseover",
String.Format("this.style.backgroundColor='{0}';",
System.Drawing.ColorTranslator.ToHtml(rollover)))
ctrl.Attributes.Add("onmouseout",
String.Format("this.style.backgroundColor='{0}';",
System.Drawing.ColorTranslator.ToHtml(initial)))
End Sub

As you can see, my code is in VB.NET, but you can obviously convert it into
C# without much trouble. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Oriane" <or****@noemail.noemailwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
Hi there,

I would like to handle a "rollover" <asp:Buttonin the code behind with
C# with this kind of code:

Button btn = Page.FindControl("Button" + numWidget) as
Button;
btn.Attributes["onmouseover"] = "document.all." +
btn.ClientID + ".src = '/Images/blue.gif'";

This code works for ImageButton...but not for Button (it does nothing).

My goal is to change the background image.

Best regards

Sep 30 '08 #2
Hi Oriane,

The ImageButton and Button differs on their underlying html representation.
You can view the html source of the asp.net page to verify that.

I agree with Nathan that you can try using javascript to change the
style.backgroundColor or style.backgroundImage attribute to acheive the
same goal.

http://bytes.com/forum/thread517432.html

http://www.webdeveloper.com/forum/ar...p/t-55226.html
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Oriane" <or****@noemail.noemail>
Subject: Rollover asp.net Button
Date: Tue, 30 Sep 2008 18:35:06 +0200
>
Hi there,

I would like to handle a "rollover" <asp:Buttonin the code behind with
C#
>with this kind of code:

Button btn = Page.FindControl("Button" + numWidget) as
Button;
btn.Attributes["onmouseover"] = "document.all." +
btn.ClientID + ".src = '/Images/blue.gif'";

This code works for ImageButton...but not for Button (it does nothing).

My goal is to change the background image.

Best regards

Oct 1 '08 #3
Thanks for your answer
Oct 1 '08 #4

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

Similar topics

5
by: Brian Angliss | last post by:
I'm relatively new to scripting in JavaScript, so I'm not too surprised I'm having difficulty scripting up an animation effect for my personal site. What I'm trying to do is the following: When...
1
by: Oxnard | last post by:
Here's the script section: function change(color){ var el=event.srcElement if (el.tagName=="INPUT"&&el.type=="button") event.srcElement.style.backgroundColor=color } function jumpto2(url){...
47
by: Lauren Quantrell | last post by:
I have constructed the following code that simulates the common rollover effect when moving the mouse over a label (this example makes the label bold.) I'm wondering if anyone has come up with...
1
by: thechaosengine | last post by:
Hi all, Can anyone tell me what I need to do to create a 3 stage rolloever button out of an asp.net image control. I don't know too much about javascript or creating user controls. I'm really...
1
by: Mike P | last post by:
what is the syntax for adding a rollover button as an image button? I have saved the button as a .swf file and put it as the ImageUrl, but since it isn't an image, do I need to save it as an image...
6
by: AJBopp | last post by:
I'm wrestling with CSS variations between Firefox and IE. I'm trying to create rollover buttons in a menu frame. It is working perfectly in Firefox but in IE only the first button is properly...
0
by: Gepi Solo | last post by:
Hi, I'm a python newbie, coming from PHP & Perl. I'm developing client-server applications with a GUI. I'm trying to realize rollover buttons with images as background. I mean... I want to create a...
2
by: eholz1 | last post by:
Hello CSS and StyleSheet members, I have decided to move away from Dreamweaver javascript rollover buttons, in favor of a CSS type rollover button. (hope that is ok). I plan to use PHP to...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.