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.

About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: