ImageButton.Enabled 属性
定义
获取或设置一个值,该值指示是否可以单击 ImageButton 以执行到服务器的回发。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; }
[<System.ComponentModel.Bindable(true)>]
[<System.ComponentModel.Browsable(true)>]
member this.Enabled : bool with get, set
Public Overrides Property Enabled As Boolean
属性值
如果启用控件,则为 true;否则为 false。true if the control is enabled; otherwise, false. 默认值为 true。The default is true.
- 属性
示例
下面的代码示例演示如何使用 Enabled 属性。The following code example demonstrates how to use the Enabled property. 此页包含两个 ImageButton 控件。The page contains two ImageButton controls. " Enabled 图像" 按钮的属性设置为 true EnabledImageButton ,使其在被单击时回发到服务器。The Enabled property is set to true for the EnabledImageButton image button, causing it to post back to the server when clicked. Enabled对于 "图像" 按钮,属性设置为 false NotEnabledImageButton ,使其在页面上呈现,但在单击时不会回发到服务器。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.
备注
下面的代码示例使用单文件代码模型,如果直接复制到代码隐藏文件中,则可能无法正常工作。The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. 必须将此代码示例复制到扩展名为 .aspx 的空文本文件中。This code sample must be copied into an empty text file that has an .aspx extension. 有关 Web 窗体代码模型的详细信息,请参阅 ASP.NET Web 窗体页代码模型。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>
注解
使用 Enabled 属性来指定是否 ImageButton 可以单击来执行回发到服务器的。Use the Enabled property to specify whether an ImageButton can be clicked to perform a post back to the server. 如果将此属性设置为 false ,则控件将在页面上呈现,但在单击时不会引发回发事件。If you set this property to false, the control renders on the page, but does not raise a post back event when clicked.