ImageButton.Enabled ImageButton.Enabled ImageButton.Enabled ImageButton.Enabled Property

Definition

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

public:
 virtual property bool Enabled { bool get(); void set(bool value); };
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.Browsable(true)]
public override bool Enabled { get; set; }
member this.Enabled : bool with get, set
Public Overrides Property Enabled As Boolean

Property Value

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

Examples

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.

Note

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>
<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  
  Sub EnabledButton_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
    
    Label1.Text = "You selected the enabled button."
        
  End Sub
  
</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>

Remarks

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.

Applies to

See also