System.Web.UI.WebControls Namespace Label Class
Sets or retrieves the text displayed for a Label control.
Inline |
<asp:label text = strtext ... > |
Script |
Label.Text [ = strtext ] |
strtext |
String that specifies the text caption for the label. |
The property is read/write with no default value.
Use the Text property to specify or determine the content displayed in a Label control.
The text of a label control can contain HTML, such as an image tag.
In certain cases, as when labels are used within templated controls, the Text property is usually obtained dynamically from a data source.
The following shows how you can programmatically set the Text property of a Label control at run time, based on user input.
void greetUser ( Object src, EventArgs e ) {
greeting.Text = "Greetings, " +
( ( userName.Text != "" ) ? userName.Text : "earthling" ) +
", welcome to ASP.NET " +
"<img src='/shared/wink.gif' width=15 height=15 border=0 alt=''>";
}
Sub greetUser ( src As Object, e As EventArgs )
greeting.Text = "Greetings, " +
IIf ( userName.Text <> "", userName.Text, "earthling" ) +
", welcome to ASP.NET " +
"<img src='/shared/wink.gif' width=15 height=15 border=0 alt=''>"
End Sub |
|
C# |
VB |
Show me
The following examples demonstrate how to dynamically bind the Text property of Label controls defined within templates.
Label Members