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; }
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.