By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,334 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,334 IT Pros & Developers. It's quick & easy.

Rollover asp.net Button

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
Thanks for your answer
Oct 1 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.