changing cursor of ImageButton

Discussion in 'ASP .Net Web Controls' started by Julia, Jun 26, 2006.

  1. Julia

    Julia Guest

    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
    Julia, Jun 26, 2006
    #1
    1. Advertising

  2. 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>



    "Julia" <> wrote in message
    news:...
    > 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
    Ken Cox [Microsoft MVP], Jun 26, 2006
    #2
    1. Advertising

  3. Julia

    Julia Guest

    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 [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" <> wrote in message
    > news:...
    > > 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

    >
    >
    >
    Julia, Jun 27, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Hearn
    Replies:
    2
    Views:
    6,077
    David Hearn
    Aug 10, 2004
  2. =?Utf-8?B?VG9tYXMgS2VwaWM=?=

    Changing DEFAULT cursor to WAIT cursor in ASP

    =?Utf-8?B?VG9tYXMgS2VwaWM=?=, Apr 5, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,317
    Bruce Barker
    Apr 5, 2005
  3. invy
    Replies:
    4
    Views:
    389
    CBFalconer
    Dec 28, 2006
  4. dmaziuk
    Replies:
    3
    Views:
    577
    Chris Gonnerman
    Jan 25, 2011
  5. Naim Rizk

    imagebutton:change the cursor from the server

    Naim Rizk, Sep 12, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    162
    Naim Rizk
    Sep 12, 2003
Loading...

Share This Page