Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Control Class
 ID Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Control..::.ID Property

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

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
<ThemeableAttribute(False)> _
Public Overridable Property ID As String
Visual Basic (Usage)
Dim instance As Control
Dim value As String

value = instance.ID

instance.ID = value
C#
[ThemeableAttribute(false)]
public virtual string ID { get; set; }
Visual C++
[ThemeableAttribute(false)]
public:
virtual property String^ ID {
    String^ get ();
    void set (String^ value);
}
JScript
public function get ID () : String
public function set ID (value : String)

Property Value

Type: System..::.String
The programmatic identifier assigned to the control.

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.

NoteNote:

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.

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker