asp.net.ph

Skip Navigation Links

Adding Label Controls to a Web Forms Page

Controls You Can Use on Web Forms   ASP.NET Standard Controls   Label Control


You can add Label Web server controls as self-standing controls on the page, or make them child controls of other controls.

To add a Label Web server control to a Web Forms page

  1. Declare an <asp:Label> element on the page. For syntax, see Label Control Syntax.
  2. Set the control’s Text property to the text to display. You can include HTML formatting or apply inline or embedded CSS stylesheets in the property; for example, you can bold an individual word in the text by placing a <B> element around it within the Text property.
<asp:Label id="myLabel" text="This is a Label control." runat="server" />

The following example shows how you can dynamically set the text of a Label control at run time. The method handles a Button control’s Click event and displays in the Label control whatever the user has typed into a TextBox control.

void setLabelText ( object src, EventArgs e ) {
   myLabel.Text = myTextBox.Text;
}
  C# VB
Label1.aspx
Run Sample | View Source
See Also

Introduction to the Label Control   Web Forms Server Controls and CSS Styles



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note