Control.ID Control.ID Control.ID Control.ID Property

定義

取得或設定指派給伺服器控制項的程式設計識別項。Gets or sets the programmatic identifier assigned to the server control.

public:
 virtual property System::String ^ ID { System::String ^ get(); void set(System::String ^ value); };
[System.Web.UI.Themeable(false)]
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.
   myControl.ID="TestControl";
   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 開發人員可以藉由ID在 ASP.NET 伺服器控制項的開頭標記中宣告屬性,來設定這個屬性。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.

適用於

另請參閱