Button 类

定义

在网页上显示按钮控件。

public ref class Button : System::Web::UI::WebControls::WebControl, System::Web::UI::IPostBackEventHandler
public ref class Button : System::Web::UI::WebControls::WebControl, System::Web::UI::IPostBackEventHandler, System::Web::UI::WebControls::IButtonControl
public class Button : System.Web.UI.WebControls.WebControl, System.Web.UI.IPostBackEventHandler
public class Button : System.Web.UI.WebControls.WebControl, System.Web.UI.IPostBackEventHandler, System.Web.UI.WebControls.IButtonControl
type Button = class
    inherit WebControl
    interface IPostBackEventHandler
type Button = class
    inherit WebControl
    interface IButtonControl
    interface IPostBackEventHandler
Public Class Button
Inherits WebControl
Implements IPostBackEventHandler
Public Class Button
Inherits WebControl
Implements IButtonControl, IPostBackEventHandler
继承
实现

示例

下面的代码示例演示如何创建一个 Submit Button 控件,该控件将网页内容发布回服务器。

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Button Example</title>
<script language="C#" runat="server">

      void SubmitBtn_Click(Object sender, EventArgs e) 
      {
         Message.Text="Hello World!!";
      }

   </script>
</head>
<body>
   <form id="form1" runat="server">

      <h3>Button Example</h3>

      Click on the submit button.<br /><br />
 
      <asp:Button id="Button1"
           Text="Submit"
           OnClick="SubmitBtn_Click" 
           runat="server"/>
       
      <br />

      <asp:label id="Message" runat="server"/>
 
   </form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Button Example</title>
<script language="VB" runat="server">
    Sub SubmitBtn_Click(sender As Object, e As EventArgs)
        Message.Text = "Hello World!!"
    End Sub 'SubmitBtn_Click
  </script>
</head>
<body>
   <form id="form1" runat="server">

      <h3>Button Example</h3>

      Click on the submit button.<br /><br />
 
      <asp:Button id="Button1"
           Text="Submit"
           OnClick="SubmitBtn_Click" 
           runat="server"/>
       
      <br />

      <asp:label id="Message" runat="server"/>
 
   </form>
</body>
</html>

下面的代码示例演示如何创建对列表进行排序的 Command Button 控件。

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Button CommandName Example</title>
<script runat="server">

      void CommandBtn_Click(Object sender, CommandEventArgs e) 
      {

         switch(e.CommandName)
         {

            case "Sort":

               // Call the method to sort the list.
               Sort_List((String)e.CommandArgument);
               break;

            case "Submit":

               // Display a message for the Submit button being clicked.
               Message.Text = "You clicked the Submit button";

               // Test whether the command argument is an empty string ("").
               if((String)e.CommandArgument == "")
               {
                  // End the message.
                  Message.Text += ".";
               }
               else
               {
                  // Display an error message for the command argument. 
                  Message.Text += ", however the command argument is not recogized.";
               }                
               break;

            default:

               // The command name is not recognized. Display an error message.
               Message.Text = "Command name not recogized.";
               break; 

         }

      }

      void Sort_List(string commandArgument)
      {

         switch(commandArgument)
         {

            case "Ascending":
 
               // Insert code to sort the list in ascending order here.
               Message.Text = "You clicked the Sort Ascending button.";
               break;

            case "Descending":
              
               // Insert code to sort the list in descending order here.
               Message.Text = "You clicked the Sort Descending button.";
               break;

            default:
        
               // The command argument is not recognized. Display an error message.
               Message.Text = "Command argument not recogized.";
               break;

         }

      }

   </script>

</head>
 
<body>

   <form id="form1" runat="server">

      <h3>Button CommandName Example</h3>

      Click on one of the command buttons.

      <br /><br />
 
      <asp:Button id="Button1"
           Text="Sort Ascending"
           CommandName="Sort"
           CommandArgument="Ascending"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

       

      <asp:Button id="Button2"
           Text="Sort Descending"
           CommandName="Sort"
           CommandArgument="Descending"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

      <br /><br />

      <asp:Button id="Button3"
           Text="Submit"
           CommandName="Submit"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

       

      <asp:Button id="Button4"
           Text="Unknown Command Name"
           CommandName="UnknownName"
           CommandArgument="UnknownArgument"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

       

      <asp:Button id="Button5"
           Text="Submit Unknown Command Argument"
           CommandName="Submit"
           CommandArgument="UnknownArgument"
           OnCommand="CommandBtn_Click" 
           runat="server"/>
       
      <br /><br />

      <asp:Label id="Message" runat="server"/>
 
   </form>
 
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Button CommandName Example</title>
<script runat="server">

      Sub CommandBtn_Click(sender As Object, e As CommandEventArgs) 

         Select e.CommandName

            Case "Sort"

               ' Call the method to sort the list.
               Sort_List(CType(e.CommandArgument, String))

            Case "Submit"

               ' Display a message for the Submit button being clicked.
               Message.Text = "You clicked the Submit button"

               ' Test whether the command argument is an empty string ("").
               If CType(e.CommandArgument , String) = "" Then
              
                  ' End the message.
                  Message.Text &= "."
               
               Else
               
                  ' Display an error message for the command argument. 
                  Message.Text &= ", however the command argument is not recogized."
               
               End If                

            Case Else

               ' The command name is not recognized. Display an error message.
               Message.Text = "Command name not recogized."

         End Select

      End Sub

      Sub Sort_List(commandArgument As String)

         Select commandArgument

            Case "Ascending"
 
               ' Insert code to sort the list in ascending order here.
               Message.Text = "You clicked the Sort Ascending button."

            Case "Descending"
              
               ' Insert code to sort the list in descending order here.
               Message.Text = "You clicked the Sort Descending button."

            Case Else
        
               ' The command argument is not recognized. Display an error message.
               Message.Text = "Command argument not recogized."

         End Select

      End Sub

   </script>

</head>
 
<body>

   <form id="form1" runat="server">

      <h3>Button CommandName Example</h3>

      Click on one of the command buttons.

      <br /><br />
 
      <asp:Button id="Button1"
           Text="Sort Ascending"
           CommandName="Sort"
           CommandArgument="Ascending"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

       

      <asp:Button id="Button2"
           Text="Sort Descending"
           CommandName="Sort"
           CommandArgument="Descending"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

      <br /><br />

      <asp:Button id="Button3"
           Text="Submit"
           CommandName="Submit"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

       

      <asp:Button id="Button4"
           Text="Unknown Command Name"
           CommandName="UnknownName"
           CommandArgument="UnknownArgument"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

       

      <asp:Button id="Button5"
           Text="Submit Unknown Command Argument"
           CommandName="Submit"
           CommandArgument="UnknownArgument"
           OnCommand="CommandBtn_Click" 
           runat="server"/>
       
      <br /><br />

      <asp:Label id="Message" runat="server"/>
 
   </form>
 
</body>
</html>

注解

本主题内容:

介绍

Button使用 控件在网页上创建一个按钮,该按钮允许用户将页面发布到服务器。 控件在服务器代码中触发事件,你可以处理该事件以响应回发。 它还可以在客户端脚本中引发一个事件,你可以在页面发布之前处理该事件,或者可以运行然后取消页面提交。

注意

ASP.NET 包括多种按钮控件,每种按钮控件在网页上的显示方式不同。 它们是 Button 作为按钮呈现的控件; LinkButton 控件(呈现为链接)和 ImageButton 控件(呈现为图像)和 ImageMap 控件,用于创建具有用户可以单击的热点的图形。 默认情况下,单击时,所有按钮控件都会提交页面。 还可以使用 HtmlButtonHtmlInputButton 控件在页面上创建在服务器代码中可编程的按钮。 有关 HTML 和 Web 服务器控件之间的差异的详细信息,请参阅 ASP.NET Web 服务器控件概述

默认情况下, Button 控件为“提交”按钮。 “提交”按钮没有命令名称 (由 CommandName 与该按钮关联的属性) 指定,只是将网页发布回服务器。 可以为事件提供事件处理程序, Click 以编程方式控制单击“提交”按钮时执行的操作。

通过设置 CommandName 属性,命令按钮具有与按钮关联的命令名称,例如 Sort。 这样,就可以在网页上创建多个 Button 控件,并通过编程方式确定单击了哪个 Button 控件。 还可以将 CommandArgument 属性与命令按钮一起使用,以提供有关要执行的命令的其他信息,例如 Ascending。 可以为事件提供事件处理程序, Command 以编程方式控制单击“命令”按钮时执行的操作。

按钮回发行为和服务器事件

当用户单击任何 Web 服务器控件按钮时,页面将发送到服务器。 这会导致处理网页,并在基于服务器的代码中引发任何挂起的事件。 当所有页面和控件处理完成后,页面将再次呈现给浏览器。

按钮可以引发自己的 Click 事件或 Command 事件,你可以使用基于服务器的代码来处理这些事件或事件。 这与传统 HTML 页面或基于客户端的 onclick Web 应用程序中的事件不同,在这些应用程序中,按钮的事件使用在客户端中运行的 JavaScript 进行处理。 有关详细信息,请参阅 ASP.NET Web Forms服务器控制事件模型

当用户单击按钮控件时,页面将发回到服务器。 默认情况下,页面发布回自身,

可以将按钮配置为将当前页发布到另一个页面。 这对于创建多页表单非常有用。 有关详细信息,请参阅 ASP.NET Web Forms 中的跨页发布

处理客户端脚本中的按钮事件

按钮控件可以引发服务器事件和客户端事件。 服务器事件在回发后发生,它们在你为页面编写的服务器端代码中进行处理。 客户端事件在客户端脚本中处理,通常为 ECMAScript (JavaScript) ,并在提交页面之前引发。 通过将客户端事件添加到 ASP.NET 按钮控件,可以执行任务,例如在提交页面之前显示确认对话框,并可能取消提交。 有关详细信息,请参阅 ASP.NET 网页 中的客户端脚本如何:在客户端脚本中响应按钮 Web 服务器控件事件

你可能还希望 Button 控件使用客户端脚本来执行回发 (,而不是在) 执行 HTTP POST 操作。 如果要以编程方式操作回发(例如将其附加到页面上的其他元素),这非常有用。 可以将 控件的 UseSubmitBehavior 属性设置为 Buttontrue使Button控件使用基于客户端脚本的回发。

按钮控件和验证

如果页面包含 ASP.NET 验证程序控件,则默认情况下,单击按钮控件会导致验证程序控件执行其检查。 如果为验证程序控件启用了客户端验证,则如果验证检查失败,则不会提交页面。

下表描述了按钮控件支持的属性,这些属性使你能够更精确地控制验证过程。

属性 说明
CausesValidation 指定单击按钮是否也执行验证检查。 将此属性设置为 false 以防止验证检查。
ValidationGroup 允许指定单击按钮时将调用页面上的验证程序。 如果未建立验证组,则单击按钮会调用页面上的所有验证程序。

有关详细信息,请参阅在 ASP.NET 网页中验证用户输入

数据控件中的按钮

按钮 Web 服务器控件通常用于数据控件,例如 DataListGridViewRepeater 列表控件。 在这些情况下,通常不会直接响应按钮单击事件。 相反,数据控件中的按钮会引发特定于数据控件的事件。 例如,在 控件中 DataList ,按钮可能会引发 DataList 控件 ItemCommand 的事件,而不是引发 Button 控件 Click 的事件。

由于数据绑定列表控件可以包含许多按钮,因此可以设置按钮的 CommandArgument 属性以指定要作为事件的一部分传递的值。 然后,可以测试此参数以查看单击了哪个按钮。

将数据绑定到控件

可以将按钮 Web 服务器控件绑定到数据源,以便动态控制其属性设置。 例如,可以使用数据绑定设置按钮的 Text 属性。

将按钮与 UpdatePanel 控件配合使用

分页呈现使无需回发即可刷新页面的部分内容。 UpdatePanel 控件使你能够标记参与部分页面呈现的页面部分。 默认情况下,控件内 UpdatePanel 控件(包括 Button 控件)的行为是执行异步回发而不是回发。 这会仅刷新源自回发的控件的内容 UpdatePanel

除了控件内的控件方案Button外,还可以在以下方案中将控件与控件配合使用UpdatePanelButtonUpdatePanel

有关部分页呈现和使用 UpdatePanel 控件的详细信息,请参阅 UpdatePanel 控件概述分页呈现概述

声明性语法

<asp:Button
    AccessKey="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CausesValidation="True|False"
    CommandArgument="string"
    CommandName="string"
    CssClass="string"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    ID="string"
    OnClick="Click event handler"
    OnClientClick="string"
    OnCommand="Command event handler"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    PostBackUrl="uri"
    runat="server"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    Text="string"
    ToolTip="string"
    UseSubmitBehavior="True|False"
    ValidationGroup="string"
    Visible="True|False"
    Width="size"
/>

构造函数

Button()

初始化 Button 类的新实例。

属性

AccessKey

获取或设置使您得以快速导航到 Web 服务器控件的访问键。

(继承自 WebControl)
Adapter

获取控件的浏览器特定适配器。

(继承自 Control)
AppRelativeTemplateSourceDirectory

获取或设置包含该控件的 PageUserControl 对象的应用程序相对虚拟目录。

(继承自 Control)
Attributes

获取与控件的特性不对应的任意特性(只用于呈现)的集合。

(继承自 WebControl)
BackColor

获取或设置 Web 服务器控件的背景色。

(继承自 WebControl)
BindingContainer

获取包含该控件的数据绑定的控件。

(继承自 Control)
BorderColor

获取或设置 Web 控件的边框颜色。

(继承自 WebControl)
BorderStyle

获取或设置 Web 服务器控件的边框样式。

(继承自 WebControl)
BorderWidth

获取或设置 Web 服务器控件的边框宽度。

(继承自 WebControl)
CausesValidation

获取或设置一个值,该值指示在单击 Button 控件时是否执行验证。

ChildControlsCreated

获取一个值,该值指示是否已创建服务器控件的子控件。

(继承自 Control)
ClientID

获取由 ASP.NET 生成的 HTML 标记的控件 ID。

(继承自 Control)
ClientIDMode

获取或设置用于生成 ClientID 属性值的算法。

(继承自 Control)
ClientIDSeparator

获取一个字符值,该值表示 ClientID 属性中使用的分隔符字符。

(继承自 Control)
CommandArgument

获取或设置可选参数,该参数与关联的 Command 一起被传递到 CommandName 事件。

CommandName

获取或设置命令名,该命令名与传递给 Button 事件的 Command 控件相关联。

Context

为当前 Web 请求获取与服务器控件关联的 HttpContext 对象。

(继承自 Control)
Controls

获取 ControlCollection 对象,该对象表示 UI 层次结构中的指定服务器控件的子控件。

(继承自 Control)
ControlStyle

获取 Web 服务器控件的样式。 此属性主要由控件开发人员使用。

(继承自 WebControl)
ControlStyleCreated

获取一个值,该值指示是否已为 Style 属性创建了 ControlStyle 对象。 此属性主要由控件开发人员使用。

(继承自 WebControl)
CssClass

获取或设置由 Web 服务器控件在客户端呈现的级联样式表 (CSS) 类。

(继承自 WebControl)
DataItemContainer

如果命名容器实现 IDataItemContainer,则获取对命名容器的引用。

(继承自 Control)
DataKeysContainer

如果命名容器实现 IDataKeysControl,则获取对命名容器的引用。

(继承自 Control)
DesignMode

获取一个值,该值指示是否正在使用设计图面上的一个控件。

(继承自 Control)
Enabled

获取或设置一个值,该值指示是否启用 Web 服务器控件。

(继承自 WebControl)
EnableTheming

获取或设置一个值,该值指示主题是否应用于该控件。

(继承自 WebControl)
EnableViewState

获取或设置一个值,该值指示服务器控件是否向发出请求的客户端保持自己的视图状态以及它所包含的任何子控件的视图状态。

(继承自 Control)
Events

获取控件的事件处理程序委托列表。 此属性为只读。

(继承自 Control)
Font

获取与 Web 服务器控件关联的字体属性。

(继承自 WebControl)
ForeColor

获取或设置 Web 服务器控件的前景色(通常是文本颜色)。

(继承自 WebControl)
HasAttributes

获取一个值,该值指示控件是否具有特性集。

(继承自 WebControl)
HasChildViewState

获取一个值,该值指示当前服务器控件的子控件是否具有任何已保存的视图状态设置。

(继承自 Control)
Height

获取或设置 Web 服务器控件的高度。

(继承自 WebControl)
ID

获取或设置分配给服务器控件的编程标识符。

(继承自 Control)
IdSeparator

获取用于分隔控件标识符的字符。

(继承自 Control)
IsChildControlStateCleared

获取一个值,该值指示该控件中包含的控件是否具有控件状态。

(继承自 Control)
IsEnabled

获取一个值,该值指示是否启用控件。

(继承自 WebControl)
IsTrackingViewState

获取一个值,用于指示服务器控件是否会将更改保存到其视图状态中。

(继承自 Control)
IsViewStateEnabled

获取一个值,该值指示是否为该控件启用了视图状态。

(继承自 Control)
LoadViewStateByID

获取一个值,该值指示控件是否通过 ID 而不是索引参与加载其视图状态。

(继承自 Control)
NamingContainer

获取对服务器控件的命名容器的引用,此引用创建唯一的命名空间,以区分具有相同 ID 属性值的服务器控件。

(继承自 Control)
OnClientClick

获取或设置在引发某个 Button 控件的 Click 事件时所执行的客户端脚本。

Page

获取对包含服务器控件的 Page 实例的引用。

(继承自 Control)
Parent

获取对页 UI 层次结构中服务器控件的父控件的引用。

(继承自 Control)
PostBackUrl

获取或设置单击 Button 控件时从当前页发送到的网页的 URL。

RenderingCompatibility

获取一个值,该值指定呈现的 HTML 将与之兼容的 ASP.NET 版本。

(继承自 Control)
Site

获取容器信息,该容器在呈现于设计图面上时承载当前控件。

(继承自 Control)
SkinID

获取或设置要应用于控件的外观。

(继承自 WebControl)
Style

获取将在 Web 服务器控件的外部标记上呈现为样式特性的文本特性的集合。

(继承自 WebControl)
SupportsDisabledAttribute

获取一个值,该值指示在控件的 disabled 属性为 IsEnabled 时,控件是否应将呈现的 HTML 元素的 false 特性设置为 "disabled"。

(继承自 WebControl)
TabIndex

获取或设置 Web 服务器控件的选项卡索引。

(继承自 WebControl)
TagKey

获取对应于此 Web 服务器控件的 HtmlTextWriterTag 值。 此属性主要由控件开发人员使用。

(继承自 WebControl)
TagName

获取控件标记的名称。 此属性主要由控件开发人员使用。

(继承自 WebControl)
TemplateControl

获取或设置对包含该控件的模板的引用。

(继承自 Control)
TemplateSourceDirectory

获取包含当前服务器控件的 PageUserControl 的虚拟目录。

(继承自 Control)
Text

获取或设置在 Button 控件中显示的文本标题。

ToolTip

获取或设置当鼠标指针悬停在 Web 服务器控件上时显示的文本。

(继承自 WebControl)
UniqueID

获取服务器控件的唯一的、以分层形式限定的标识符。

(继承自 Control)
UseSubmitBehavior

获取或设置一个布尔值,该值指示 Button 控件使用客户端浏览器的提交机制还是 ASP.NET 回发机制。

ValidateRequestMode

获取或设置指示控件是否检查来自浏览器的客户端输入是否具有潜在危险值的值。

(继承自 Control)
ValidationGroup

获取或设置在 Button 控件回发到服务器时导致验证的控件组。

ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原服务器控件的视图状态。

(继承自 Control)
ViewStateIgnoresCase

获取一个值,该值指示 StateBag 对象是否不区分大小写。

(继承自 Control)
ViewStateMode

获取或设置此控件的视图状态模式。

(继承自 Control)
Visible

获取或设置一个值,该值指示服务器控件是否作为 UI 呈现在页上。

(继承自 Control)
Width

获取或设置 Web 服务器控件的宽度。

(继承自 WebControl)

方法

AddAttributesToRender(HtmlTextWriter)

Button 控件的特性添加到输出流用以在客户端上呈现内容。

AddedControl(Control, Int32)

在子控件添加到 Control 对象的 Controls 集合后调用。

(继承自 Control)
AddParsedSubObject(Object)

通知服务器控件,分析了一个元素(XML 或 HTML),并将该元素添加到服务器控件的 ControlCollection 对象中。

(继承自 Control)
ApplyStyle(Style)

将指定样式的所有非空白元素复制到 Web 控件,覆盖控件的所有现有的样式元素。 此方法主要由控件开发人员使用。

(继承自 WebControl)
ApplyStyleSheetSkin(Page)

将页样式表中定义的样式属性应用到控件。

(继承自 Control)
BeginRenderTracing(TextWriter, Object)

开始输出数据的设计时追踪。

(继承自 Control)
BuildProfileTree(String, Boolean)

收集有关服务器控件的信息并将该信息发送到 Trace 属性,在启用页的跟踪功能时将显示该属性。

(继承自 Control)
ClearCachedClientID()

将缓存的 ClientID 值设置为 null

(继承自 Control)
ClearChildControlState()

删除服务器控件的子控件的控件状态信息。

(继承自 Control)
ClearChildState()

删除服务器控件的所有子控件的视图状态和控件状态信息。

(继承自 Control)
ClearChildViewState()

删除服务器控件的所有子控件的视图状态信息。

(继承自 Control)
ClearEffectiveClientIDMode()

将当前控件实例和任何子控件的 ClientIDMode 属性设置为 Inherit

(继承自 Control)
CopyBaseAttributes(WebControl)

Style 对象未封装的属性从指定的 Web 服务器控件复制到从中调用此方法的 Web 服务器控件。 此方法主要由控件开发人员使用。

(继承自 WebControl)
CreateChildControls()

由 ASP.NET 页框架调用,以通知服务器控件在准备回发或呈现时使用基于撰写的实现来创建其所包含任何子控件。

(继承自 Control)
CreateControlCollection()

创建一个新 ControlCollection 对象来保存服务器控件的子控件(包括文本控件和服务器控件)。

(继承自 Control)
CreateControlStyle()

创建由 WebControl 类在内部用来实现所有与样式有关的属性的样式对象。 此方法主要由控件开发人员使用。

(继承自 WebControl)
DataBind()

将数据源绑定到调用的服务器控件及其所有子控件。

(继承自 Control)
DataBind(Boolean)

将数据源绑定到调用的服务器控件及其所有子控件,同时可以选择引发 DataBinding 事件。

(继承自 Control)
DataBindChildren()

将数据源绑定到服务器控件的子控件。

(继承自 Control)
Dispose()

使服务器控件得以在从内存中释放之前执行最后的清理操作。

(继承自 Control)
EndRenderTracing(TextWriter, Object)

结束输出数据的设计时追踪。

(继承自 Control)
EnsureChildControls()

确定服务器控件是否包含子控件。 如果不包含,则创建子控件。

(继承自 Control)
EnsureID()

为尚未分配标识符的控件创建标识符。

(继承自 Control)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
FindControl(String)

在当前的命名容器中搜索带指定 id 参数的服务器控件。

(继承自 Control)
FindControl(String, Int32)

使用指定的 idpathOffset 参数(该参数有助于搜索)中指定的整数在当前命名容器中搜索服务器控件。 不应重写此版本的 FindControl 方法。

(继承自 Control)
Focus()

为控件设置输入焦点。

(继承自 Control)
GetDesignModeState()

获取控件的设计时数据。

(继承自 Control)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetPostBackOptions()

创建表示 PostBackOptions 控件的回发行为的 Button 对象。

GetRouteUrl(Object)

获取与一组路由参数对应的 URL。

(继承自 Control)
GetRouteUrl(RouteValueDictionary)

获取与一组路由参数对应的 URL。

(继承自 Control)
GetRouteUrl(String, Object)

获取与一组路由参数以及某个路由名称对应的 URL。

(继承自 Control)
GetRouteUrl(String, RouteValueDictionary)

获取与一组路由参数以及某个路由名称对应的 URL。

(继承自 Control)
GetType()

获取当前实例的 Type

(继承自 Object)
GetUniqueIDRelativeTo(Control)

返回指定控件的 UniqueID 属性的前缀部分。

(继承自 Control)
HasControls()

确定服务器控件是否包含任何子控件。

(继承自 Control)
HasEvents()

返回一个值,该值指示是否为控件或任何子控件注册事件。

(继承自 Control)
IsLiteralContent()

确定服务器控件是否只包含文字内容。

(继承自 Control)
LoadControlState(Object)

SaveControlState() 方法保存的上一个页请求还原控件状态信息。

(继承自 Control)
LoadViewState(Object)

从使用 SaveViewState() 方法保存的前一请求还原视图状态信息。

(继承自 WebControl)
MapPathSecure(String)

检索虚拟路径(绝对的或相对的)映射到的物理路径。

(继承自 Control)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MergeStyle(Style)

将指定样式的所有非空白元素复制到 Web 控件,但不覆盖该控件现有的任何样式元素。 此方法主要由控件开发人员使用。

(继承自 WebControl)
OnBubbleEvent(Object, EventArgs)

确定服务器控件的事件是否沿页的 UI 服务器控件层次结构向上传递。

(继承自 Control)
OnClick(EventArgs)

引发 Button 控件的 Click 事件。

OnCommand(CommandEventArgs)

引发 Button 控件的 Command 事件。

OnDataBinding(EventArgs)

引发 DataBinding 事件。

(继承自 Control)
OnInit(EventArgs)

引发 Init 事件。

(继承自 Control)
OnLoad(EventArgs)

引发 Load 事件。

(继承自 Control)
OnPreRender(EventArgs)

确定按钮在客户端上呈现之前是否已被单击。

OnPreRender(EventArgs)

引发 PreRender 事件。

(继承自 Control)
OnUnload(EventArgs)

引发 Unload 事件。

(继承自 Control)
OpenFile(String)

获取用于读取文件的 Stream

(继承自 Control)
RaiseBubbleEvent(Object, EventArgs)

将所有事件源及其信息分配给控件的父级。

(继承自 Control)
RaisePostBackEvent(String)

Button 控件回发到服务器时引发此控件的事件。

RemovedControl(Control)

Control 对象的 Controls 集合移除子控件后调用。

(继承自 Control)
Render(HtmlTextWriter)

将控件呈现给指定的 HTML 编写器。

(继承自 WebControl)
RenderBeginTag(HtmlTextWriter)

将控件的 HTML 开始标记呈现到指定的编写器中。 此方法主要由控件开发人员使用。

(继承自 WebControl)
RenderChildren(HtmlTextWriter)

将服务器控件子级的内容输出到提供的 HtmlTextWriter 对象,该对象可写入要在客户端上呈现的内容。

(继承自 Control)
RenderContents(HtmlTextWriter)

将控件的内容呈现到指定的编写器中。

RenderControl(HtmlTextWriter)

将服务器控件内容输出到所提供的 HtmlTextWriter 对象,如果启用了跟踪,则还将存储有关该控件的跟踪信息。

(继承自 Control)
RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 对象将服务器控件内容输出到提供的 ControlAdapter 对象。

(继承自 Control)
RenderEndTag(HtmlTextWriter)

将控件的 HTML 结束标记呈现到指定的编写器中。 此方法主要由控件开发人员使用。

(继承自 WebControl)
ResolveAdapter()

获取负责呈现指定控件的控件适配器。

(继承自 Control)
ResolveClientUrl(String)

获取浏览器可以使用的 URL。

(继承自 Control)
ResolveUrl(String)

将 URL 转换为在请求客户端可用的 URL。

(继承自 Control)
SaveControlState()

保存将页面回发到服务器之后发生的所有服务器控件状态更改。

(继承自 Control)
SaveViewState()

保存调用 TrackViewState() 方法后修改的任何状态。

(继承自 WebControl)
SetDesignModeState(IDictionary)

为控件设置设计时数据。

(继承自 Control)
SetRenderMethodDelegate(RenderMethod)

分配事件处理程序委托,以将服务器控件及其内容呈现到父控件中。

(继承自 Control)
SetTraceData(Object, Object)

使用跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。

(继承自 Control)
SetTraceData(Object, Object, Object)

使用跟踪对象、跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。

(继承自 Control)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
TrackViewState()

使控件跟踪其视图状态的更改,以便将这些更改存储在对象的 ViewState 属性中。

(继承自 WebControl)

事件

Click

在单击 Button 控件时发生。

Command

在单击 Button 控件时发生。

DataBinding

当服务器控件绑定到数据源时发生。

(继承自 Control)
Disposed

当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。

(继承自 Control)
Init

当服务器控件初始化时发生;初始化是控件生存期的第一步。

(继承自 Control)
Load

当服务器控件加载到 Page 对象中时发生。

(继承自 Control)
PreRender

在加载 Control 对象之后、呈现之前发生。

(继承自 Control)
Unload

当服务器控件从内存中卸载时发生。

(继承自 Control)

显式接口实现

IAttributeAccessor.GetAttribute(String)

获取具有指定名称的 Web 控件的特性。

(继承自 WebControl)
IAttributeAccessor.SetAttribute(String, String)

将 Web 控件的特性设置为指定的名称和值。

(继承自 WebControl)
IControlBuilderAccessor.ControlBuilder

有关此成员的说明,请参见 ControlBuilder

(继承自 Control)
IControlDesignerAccessor.GetDesignModeState()

有关此成员的说明,请参见 GetDesignModeState()

(继承自 Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

有关此成员的说明,请参见 SetDesignModeState(IDictionary)

(继承自 Control)
IControlDesignerAccessor.SetOwnerControl(Control)

有关此成员的说明,请参见 SetOwnerControl(Control)

(继承自 Control)
IControlDesignerAccessor.UserData

有关此成员的说明,请参见 UserData

(继承自 Control)
IDataBindingsAccessor.DataBindings

有关此成员的说明,请参见 DataBindings

(继承自 Control)
IDataBindingsAccessor.HasDataBindings

有关此成员的说明,请参见 HasDataBindings

(继承自 Control)
IExpressionsAccessor.Expressions

有关此成员的说明,请参见 Expressions

(继承自 Control)
IExpressionsAccessor.HasExpressions

有关此成员的说明,请参见 HasExpressions

(继承自 Control)
IParserAccessor.AddParsedSubObject(Object)

有关此成员的说明,请参见 AddParsedSubObject(Object)

(继承自 Control)
IPostBackEventHandler.RaisePostBackEvent(String)

Button 控件回发到服务器时引发此控件的事件。

扩展方法

FindDataSourceControl(Control)

返回与指定控件的数据控件关联的数据源。

FindFieldTemplate(Control, String)

返回指定控件的命名容器中指定列的字段模板。

FindMetaTable(Control)

返回包含数据控件的元表对象。

适用于

另请参阅