HTML server controls are HTML elements containing attributes that make them visible to — and programmable on — the Web server.
These controls enable page developers to dynamically access and manipulate HTML elements within a Web Forms page.
Any HTML element can be converted to an HTML control, simply by adding a runat="server" attribute and an id attribute to uniquely identify the HTML element.
<htmlelement id="uniqueID" runat="server">
The Web Forms framework, though, provides pre-defined HTML server controls for the HTML elements most commonly used dynamically on a page.
These include the HTML <form
>, the HTML <input
> elements ( text box, check box, radio button, submit button, and so on ), the HTML <select
>, <table
>, <image
>, and so on.
These pre-defined HTML server controls share the basic properties of the standard HTML element, and in certain cases provide their own set of properties and events.
In addition, any other HTML element that does not explicitly map to one of the ASP.NET HTML server controls is handled by an HtmlGenericControl.
By assigning a unique id to the control, the control’s methods and properties can then be accessed programmatically, using the control’’s assigned identifier.
The below code snippet demonstrates how to dynamically set the InnerHtml property of an HTML <span runat="server"
> control as the page loads.
<script language="C#" runat="server">
void Page_Load ( Object sender, EventArgs e ) {
myCtrl.InnerHtml = "Today is " + DateTime.Now.ToString ( "f" );
}
</script>
...
<span id="myCtrl" style="font-style:italic" runat="server" />
<script language="VB" runat="server">
Sub Page_Load ( sender As Object, e As EventArgs )
myCtrl.InnerHtml = "Today is " + DateTime.Now.ToString ( "f" )
End Sub
</script>
...
<span id="myCtrl" style="font-style:italic" runat="server" />
<script language="JScript" runat="server">
function Page_Load ( sender:Object, e:EventArgs ) : void {
myCtrl.InnerHtml = "Today is " + DateTime.Now.ToString ( "f" );
}
</script>
...
<span id="myCtrl" style="font-style:italic" runat="server" /> |
|
C# |
VB |
JScript |
For a quick overview of the available ASP.NET HTML controls, see HTML Server Controls.