Export (0) Print
Expand All

Control.ID Property

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

[Visual Basic]
Public Overridable Property ID As String
[C#]
public virtual string ID {get; set;}
[C++]
public: __property virtual String* get_ID();
public: __property virtual void set_ID(String*);
[JScript]
public function get ID() : String;
public function set ID(String);

Property Value

The programmatic identifier assigned to the control.

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   Including spaces in this property will cause an ASP.NET page parser error.

Example

[Visual Basic] 
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

[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);
}

[C++] 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Web.UI Namespace | Control.NamingContainer | INamingContainer

Show:
© 2014 Microsoft