June 6, 2009

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.



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP 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 has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "Change the Default Cursor on an ASP.net Image Button"
 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions