ASP.NET Syntax ASP.NET Syntax for Web Controls
Displays static text on the Web Forms page and allows you to manipulate it programmatically.
Declarative Syntax
<asp:Label
AccessKey = "string"
AssociatedControlID = "string"
BackColor = "color name | #dddddd"
BorderColor = "color name | #dddddd"
BorderStyle = "NotSet | None | Dotted | Dashed | Solid | Double | Groove |
Ridge | Inset | Outset"
BorderWidth = size
CssClass = "string"
Enabled = "True | False"
EnableTheming = "True | False"
EnableViewState = "True | False"
Font-Bold = "True | False"
Font-Italic = "True | False"
Font-Names = "string"
Font-Overline = "True | False"
Font-Size = "string | Smaller | Larger | XX-Small | X-Small | Small |
Medium | Large | X-Large | XX-Large"
Font-Strikeout = "True | False"
Font-Underline = "True | False"
ForeColor = "color name | #dddddd"
Height = size
ID = "string"
OnDataBinding = "DataBinding event handler"
OnDisposed = "Disposed event handler"
OnInit = "Init event handler"
OnLoad = "Load event handler"
OnPreRender = "PreRender event handler"
OnUnload = "Unload event handler"
runat = "server"
SkinID = "string"
Style = "string"
TabIndex = integer
Text = "string"
ToolTip = "string"
Visible = "True | False"
Width = size
/>
NOTE: The content of an <asp:Label
> control can be defined within its opening tag. In this case, you can close the start tag with a trailing slash />
instead of using a separate end tag.
For information on the individual members of this class, see Label in the class library.
The Label control renders text in a set location on a Web Forms page. Unlike static text, you can customize the displayed text by setting the Text property.
The below code snippet demonstrates how to use a Label control to display the coordinates on an image where the user clicks.
<script language="C#" runat="server">
void getImageCoords ( object Source, ImageClickEventArgs e ) {
msgLabel.Text = "You clicked the ImageButton control at the " +
coordinates: ( " + e.X.ToString ( ) + ", " +
e.Y.ToString ( ) + " ) ";
}
</script>
<script runat="server">
Sub getImageCoords ( sender As Object, e As ImageClickEventArgs )
msgLabel.Text = "You clicked the ImageButton control at the " & _
Coordinates: ( " & e.X.ToString ( ) & ", " & _
e.Y.ToString ( ) & " ) "
End Sub
</script> |
|
C# |
VB |
<form runat="server">
<asp:ImageButton id="imagebutton1" runat="server"
AlternateText = "ImageButton 1"
ImageAlign = "left"
ImageUrl = "images/pict.jpg"
onClick = "getImageCoords" />
<p><asp:Label id="msgLabel" runat="server" />
</form>
Label Class Label Web Server Control