Label Constructor
.NET Framework 2.0
Initializes a new instance of the Label class.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Label Members
System.Web.UI.WebControls Namespace
How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings
ASP.NET Web Page Code Model
Label Web Server Control
How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings
Assembly: System.Web (in system.web.dll)
The following example shows how to create and initialize a new instance of the Label control.
![]() |
---|
The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model. |
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script language="C#" runat="server"> void Button1_Click(Object Sender, EventArgs e) { Label myLabel = new Label(); myLabel.Text = "This is a new Label"; Page.Controls.Add(myLabel); } </script> </head> <body> <form runat="server"> <h3>Label Example</h3> <asp:Button id="Button1" Text="Create and Show a Label" OnClick="Button1_Click" runat="server"/> </form> </body> </html>
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
Label ClassLabel Members
System.Web.UI.WebControls Namespace
Other Resources
Label Web Server ControlHow to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings
ASP.NET Web Page Code Model
Label Web Server Control
How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings
Show: