Control.ID 属性


获取或设置分配给服务器控件的编程标识符。Gets or sets the programmatic identifier assigned to the server control.

 virtual property System::String ^ ID { System::String ^ get(); void set(System::String ^ value); };
public virtual string ID { get; set; }
public virtual string ID { get; set; }
member this.ID : string with get, set
Public Overridable Property ID As String



分配给控件的编程标识符。The programmatic identifier assigned to the control.



void Page_Init(object sender,EventArgs e)
   // Add a event Handler for 'Init'.
   myControl.Init += new System.EventHandler(Control_Init);

void Control_Init(object sender,EventArgs e)
  Response.Write("The ID of the object initially : " + myControl.ID);      
  // Change the ID property.
   Response.Write("<br />The changed ID : " + myControl.ID);
Sub Page_Init(sender As Object, e As EventArgs)
   ' Add a event Handler for 'Init'.
   AddHandler myControl.Init, AddressOf Control_Init
End Sub

Sub Control_Init(sender As Object, e As EventArgs)
   Response.Write(("The ID of the object initially : " + myControl.ID))
   ' Change the ID property.
   myControl.ID = "TestControl"
   Response.Write(("<br />The changed ID : " + myControl.ID))
End Sub


在服务器控件上设置此属性可提供对服务器控件的属性、事件和方法的编程访问。Setting this property on a server control provides you with programmatic access to the server control's properties, events, and methods. Web 开发人员可以通过在 ASP.NET 服务器控件的开始标记中声明 ID 特性来设置此属性。This property can be set by Web developers by declaring an ID attribute in the opening tag of an ASP.NET server control.

如果未以声明方式或编程方式为服务器控件指定此属性,则可以通过其父控件的 Controls 属性获取对该控件的引用。If this property is not specified for a server control, either declaratively or programmatically, you can obtain a reference to the control through its parent control's Controls property.


只有字母数字字符和下划线字符(_)的组合是此属性的有效值。Only combinations of alphanumeric characters and the underscore character ( _ ) are valid values for this property. 包括空格或其他无效字符将导致 ASP.NET 页分析器错误。Including spaces or other invalid characters will cause an ASP.NET page parser error.