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