Change the Default Cursor on an Image Button

How do you change the default cursor when the mouse is hovered over an ASP.NET Image Button? Here’s how to do so in a simple way:

asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/progress.gif" />


protected void Page_Load(object sender, EventArgs e)
if (1 == 1)


Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As EventArgs)
If 1 = 1 Then
ImageButton1.Style.Add(HtmlTextWriterStyle.Cursor, _
End If
End Sub

You can also create CSS in the following way:

<style type="text/css">
cursor: url('Images.cur');

cursor: url('3dwno.cur');

and change the CSS of the image button in code behind / JavaScript based on the condition.

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: