changing cursor of ImageButton

J

Julia

Hi

I have developed a composite control containing an ImageButton. The user can
only press the ImageButton at some point. I would like to make the cursor of
the ImageButton normal all the time the ImageButton is not possible to press.
How do I do that?

Thanks in advance
Julia
 
K

Ken Cox [Microsoft MVP]

Hi Julia,

If you set the image button's enabled property to false, the cursor should
stay at the default.

In a user control, you have to get a reference to the image button. Here's
some sample code (ASP.NET 2.0) in case it helps.

Let us know how you make out?

Ken
Microsoft MVP [ASP.NET]


' --imgbtn.ascx--

<%@ control classname="usrimgbtn" language="VB" %>

<asp:imagebutton id="ImageButton1" runat="server"
imageurl="http://www.gc.ca/images/flag.gif" /><br />
<br />
<asp:label id="lblEnabled" runat="server"></asp:label>


'-- imgbtncursor.aspx--
<%@ Page Language="VB" %>

<%@ register src="imgbtn.ascx" tagname="imgbtn" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub btnEnableDisable_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim uc As UserControl
Dim imgbtn As ImageButton
Dim lbl As Label
uc = Page.FindControl("Imgbtn1")
If Not IsNothing(uc) Then
imgbtn = uc.FindControl("ImageButton1")
lbl = uc.FindControl("lblEnabled")
imgbtn.Enabled = Not imgbtn.Enabled
lbl.Text = imgbtn.Enabled.ToString
btnEnableDisable.Text = _
IIf(imgbtn.Enabled, "Disable", "Enable")
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Enable Disable button</title>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;<br />
<uc1:imgbtn id="Imgbtn1" runat="server" />
<br />
<br />
<asp:button id="btnEnableDisable" runat="server"
onclick="btnEnableDisable_Click" text="Disable" />&nbsp;</div>
</form>
</body>
</html>
 
J

Julia

Hi

It did not work to just set the ImageButton's enable property to false. I
also write all my code in C# so I dont write any asp.net.

But I have solved my problem by using StyleSheet like this:

..ImageButtonEnable
{
padding-left:5px;
padding-right:5px;
padding-top:5px;
}
..ImageButtonDisable
{
padding-left:5px;
padding-right:5px;
padding-top:5px;
cursor:default;
}

I dont know if it the best way to do but it works ;)

Thanks
Julia

Ken Cox said:
Hi Julia,

If you set the image button's enabled property to false, the cursor should
stay at the default.

In a user control, you have to get a reference to the image button. Here's
some sample code (ASP.NET 2.0) in case it helps.

Let us know how you make out?

Ken
Microsoft MVP [ASP.NET]


' --imgbtn.ascx--

<%@ control classname="usrimgbtn" language="VB" %>

<asp:imagebutton id="ImageButton1" runat="server"
imageurl="http://www.gc.ca/images/flag.gif" /><br />
<br />
<asp:label id="lblEnabled" runat="server"></asp:label>


'-- imgbtncursor.aspx--
<%@ Page Language="VB" %>

<%@ register src="imgbtn.ascx" tagname="imgbtn" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub btnEnableDisable_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim uc As UserControl
Dim imgbtn As ImageButton
Dim lbl As Label
uc = Page.FindControl("Imgbtn1")
If Not IsNothing(uc) Then
imgbtn = uc.FindControl("ImageButton1")
lbl = uc.FindControl("lblEnabled")
imgbtn.Enabled = Not imgbtn.Enabled
lbl.Text = imgbtn.Enabled.ToString
btnEnableDisable.Text = _
IIf(imgbtn.Enabled, "Disable", "Enable")
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Enable Disable button</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<uc1:imgbtn id="Imgbtn1" runat="server" />
<br />
<br />
<asp:button id="btnEnableDisable" runat="server"
onclick="btnEnableDisable_Click" text="Disable" /> </div>
</form>
</body>
</html>



Julia said:
Hi

I have developed a composite control containing an ImageButton. The user
can
only press the ImageButton at some point. I would like to make the cursor
of
the ImageButton normal all the time the ImageButton is not possible to
press.
How do I do that?

Thanks in advance
Julia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top