ImageButton.Enabled Property

 

Gets or sets a value indicating whether the ImageButton can be clicked to perform a post back to the server.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[BrowsableAttribute(true)]
[BindableAttribute(true)]
public override bool Enabled { get; set; }

Property Value

Type: System.Boolean

true if the control is enabled; otherwise, false. The default is true.

Use the Enabled property to specify whether an ImageButton can be clicked to perform a post back to the server. If you set this property to false, the control renders on the page, but does not raise a post back event when clicked.

The following code example demonstrates how to use the Enabled property. The page contains two ImageButton controls. The Enabled property is set to true for the EnabledImageButton image button, causing it to post back to the server when clicked. The Enabled property is set to false for the NotEnabledImageButton image button, causing it to render on the page, but not post back to the server when clicked.

System_CAPS_noteNote

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

<%@ page language="C#"%>

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

  void EnabledButton_Click (object sender, ImageClickEventArgs e)
  {
    Label1.Text = "You selected the enabled button.";
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>ImageButton.Enabled Example</title>
</head>
<body>
  <form id="form1" runat="server">

    <h3>ImageButton.Enabled Example</h3>

    <asp:imagebutton id="EnabledImageButton"
      enabled="true"
      alternatetext="Enabled Button"
      imageurl="Images\EnabledButton.jpg"
      onclick="EnabledButton_Click"
      runat="Server">
    </asp:imagebutton>

    <br /><br /><br />    

    <asp:imagebutton id="NotEnabledImageButton"
      enabled="false"
      alternatetext="Not Enabled Button"
      imageurl="Images\NotEnabledButton.jpg"
      runat="Server">
    </asp:imagebutton> 

    <br /><br />

    <asp:label id="Label1"
      runat="Server">
    </asp:label>

  </form>
</body>
</html>

.NET Framework
Available since 2.0
Return to top
Show: