|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.|
How to: Add Label Web Server Controls to a Web Forms Page
You can add Label Web server controls as self-standing controls on your ASP.NET Web page. You can also make Label controls child controls of other controls, such as using them in Web server control templates. For details, see ASP.NET Web Server Controls Templates.
To add a Label Web server control to a Web Forms page
From the Standard tab of the Toolbox, drag a Label control onto the page.
In the Appearance category of the Properties window, set the control's Text property to the text to display. You can include HTML formatting in the property; for example, you can format an individual word in the text as bold by placing a <b> tag around it in the Text property.
Be careful when using the Label control to display strings that come from an untrusted source. They can include potentially malicious client script. For details, see How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings.
Protected Sub Button1_Click(ByVal sender as Object, _ ByVal e as EventArgs) Label1.Text = Server.HtmlEncode(TextBox1.Text) End Sub