Home All Groups Group Topic Archive Search About
Author
26 Jun 2006 11:59 AM
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

Author
26 Jun 2006 4:42 PM
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>



Show quoteHide quote
"Julia" <Ju***@discussions.microsoft.com> wrote in message
news:C9325A61-EB9B-410F-B278-9637E6515BDF@microsoft.com...
> 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
Author
27 Jun 2006 10:01 AM
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

Show quoteHide quote
"Ken Cox [Microsoft MVP]" wrote:

> 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" <Ju***@discussions.microsoft.com> wrote in message
> news:C9325A61-EB9B-410F-B278-9637E6515BDF@microsoft.com...
> > 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
>
>
>