Control.ID Property

Definition

Gets or sets the programmatic identifier assigned to the server control.

C#
public virtual string ID { get; set; }
C#
[System.Web.UI.Themeable(false)]
public virtual string ID { get; set; }

Property Value

The programmatic identifier assigned to the control.

Attributes

Examples

C#
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);
}

Remarks

Setting this property on a server control provides you with programmatic access to the server control's properties, events, and methods. This property can be set by Web developers by declaring an ID attribute in the opening tag of an ASP.NET server control.

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.

Note

Only combinations of alphanumeric characters and the underscore character ( _ ) are valid values for this property. Including spaces or other invalid characters will cause an ASP.NET page parser error.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also