|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
How to: Add Label Web Server Controls to a Web Forms Page
You can addWeb server controls as self-standing controls on the page. You can also make them child controls of other controls, for example by using them in .
If you want to display static text, you can present it using HTML; you do not need a Label control. Use a Label control only if you need to change the contents or other characteristics of the text in server code.
To add a Label Web server control to a Web Forms page
Type an <asp:Label> element into the page. For syntax, see Label Web Server Control.
Set the control'sproperty to the text to display. You can include HTML formatting in the property; for example, you can bold an individual word in the text by placing a <b> element around it in the Text property.
The following code example shows how you can set the text of a Label control at run time. The method displays in the Label control whatever the user has typed into acontrol called
Be careful when using strings that come from an untrusted source; they can include potentially malicious client script. For details, see.
Private Sub Button1_Click(ByVal sender as Object, _ ByVal e as EventArgs) Label1.Text = Server.HtmlEncode(TextBox1.Text) End Sub