Change the Default Cursor on an ASP.net 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:

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


C#



protected void Page_Load(object sender, EventArgs e)
{
if (1 == 1)
{
ImageButton1.Style.Add(HtmlTextWriterStyle.Cursor,
"url('3dwno.cur')");
}
}


VB.NET



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



You can also create CSS in the following way:



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

.second{
cursor: url('3dwno.cur');
}
</style>



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: