Link to home
Start Free TrialLog in
Avatar of Mr_Shaw
Mr_Shaw

asked on

C# hover button with code

I am trying to do a hover feature with my button.

I have set the button up as

  <asp:Button ID="Button1" runat="server" BackColor="#0099CC" BorderStyle="None"
        onclick="Button1_Click" Text="Button" OnMouseEnter="Button1_MouseEntr" OnMouseLeave="Button1_MouseLve"
        />

and have the code as

 private void Button1_MouseEntr(object sender, EventArgs e)
    {
        Button1.BackColor = System.Drawing.Color.Red;
    }

but nothing is happening.

Does anybody know?
Avatar of mahadevan_v
mahadevan_v

you can write javascript for doing this
create 2 javascript functions
 1.changes color of the button
2. resets the button to its original color

Call the functions on onmouseenter and onmouseleave events

To add the events to button use
button.Attributes.Add("onmouseenter","function name ");
in the server side code
Avatar of Mr_Shaw

ASKER

Ok... i am not the best at codeing with javascript ...

my requirement is:

to create a set of tabs using buttons.

The user passes over a button where there will be a rollover effect (change color/image).

The use then clicks the button and then it permantly changes color until another button is clicked.

There is no server side event for mouse events in asp.net.

You are calling the OnMouseEnter (which is a java script and client side event), it will not be executed on Server side.

What you have to do is either create a javascript method or use style sheets (CSS) to achieve this functionality.

If you got my point than i will clarify it further in next post.

Avatar of Mr_Shaw

ASKER

yes i get your point, please continue
ASKER CERTIFIED SOLUTION
Avatar of mahadevan_v
mahadevan_v

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial