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.
- Declare an <
asp:Label
> element on the page. For syntax, see Label Control Syntax.
- 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;
}
Sub setLabelText ( ByVal sender as Object, ByVal e as EventArgs )
myLabel.Text = myTextBox.Text
End Sub |
|
C# |
VB |
Introduction to the Label Control Web Forms Server Controls and CSS Styles