Web server controls are custom ASP.NET controls with more built-in features than HTML server controls.
Web server controls include not only form-type controls such as text boxes and buttons, but also controls to display data-bound lists, and special-purpose controls such as a calendar, menu, treeview and ad rotator.
Web server controls are more abstract and flexible than HTML server controls, in that their object model does not necessarily reflect HTML syntax.
Web server controls are declared with an XML tag prefix that references the asp namespace.
<asp:label ... runat="server" />
By assigning a unique id attribute to the control, the control’s methods and properties can then be accessed programmatically, using the control’s assigned name.
The below code snippet demonstrates how to dynamically set the Text property of a Label control as the page loads.
<script language="C#" runat="server">
void Page_Load ( Object sender, EventArgs e ) {
myCtrl.Text= "Today is " + DateTime.Now.ToString ( "f" );
}
</script>
...
<asp:label id="myCtrl" style="font-style:italic" runat="server" />
<script language="VB" runat="server">
Sub Page_Load ( sender As Object, e As EventArgs )
myCtrl.Text= "Today is " + DateTime.Now.ToString ( "f" )
End Sub
</script>
...
<asp:label id="myCtrl" style="font-style:italic" runat="server" />
<script language="JScript" runat="server">
function Page_Load ( sender:Object, e:EventArgs ) : void {
myCtrl.Text= "Today is " + DateTime.Now.ToString ( "f" );
}
</script>
...
<asp:label id="myCtrl" style="font-style:italic" runat="server" /> |
|
C# |
VB |
JScript |
For an overview of the available ASP.NET Web controls, see Controls You Can Use on Web Forms.