Slide 13.6: Server controls
Slide 13.8: HTML server controls (cont.)
Home

HTML Server Controls


The following example declares two HtmlAnchor server controls, which allow programmatic access to the HTML <a> tag on the server. For example,
   <a id="link1" runat="server">
The executable code itself has been moved outside the HTML and put in the section
   <script runat="server">
The Page_Load event is triggered when a page loads. It manipulates the following attributes of the HtmlAnchor:

demo_htmlanchor.aspx

Web
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script language="C#" runat="server">
 protected void Page_Load( object sender, EventArgs e ) {
  link1.HRef="http://www.w3schools.com";
  link1.Target="_blank";
  link1.Title="W3Schools";
  link2.HRef="http://www.microsoft.com";
  link2.Target="_blank";
  link2.Title="Microsoft";
 }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" > 
 <body>
  <form runat="server">
   <a id="link1" runat="server">Visit W3Schools!</a>
   <a id="link2" runat="server">Visit Microsoft!</a>
  </form>
 </body>
</html>