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.

No comments:

Post a Comment