1. Computing

Learn ASP.NET 2.0 - ASP.NET 2.0 Server Controls

The Syntax of the ASP.NET Server Control

From , former About.com Guide

The "asp:" part of the HTML statement refers to the asp "namespace". All server controls are objects in the System.Web.UI namespace in the .NET Framework.

You can also run standard HTML controls at the server but this doesn't make them server controls. But it does make them available to your VB.NET program. For example, if you add this code to the Default.aspx file in Source view (notice: no "asp:" namespace prefix) ...

<body>
   <form id="form1" runat="server">
   <div>
   <button id="AVBButton" runat="server"></button>
   </div>
   </form>
</body>

... you can write code to modify this HTML button at the server. This code in the Page Load event ...

AVBButton.InnerText = _
   "An HTML Button executed at the server."

... results in this web page:

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

Why is it important that these controls be able to execute code at the server? Mainly because that's where the data is.

Suppose a website has a button that finds information in a database. Since the database is only directly accessible to the server, code on the server can make decisions about what to return. For example, if one part of the data is missing, server based code can substitute default values, return an error, or look in a different location.

The HTML objects that ASP.NET sends to the browser often "post back" to the server for more processing. The .NET Framework then provides a rich set of events that can be used, just like Windows forms. For example, the Button class supports ...

  • Click
  • Command
  • DataBinding
  • Disposed
  • Init
  • Load
  • PreRender
  • Unload

Keep in mind that this is not the same "button" that you use on Windows Forms. ASP.NET server controls are completely separate from Windows Forms controls. That's because there are completely separate requirements for ASP.NET controls. Some of the unique types of controls that are available with ASP.NET include:

  • Validation Controls
    These controls let you validate web form data before the data is submitted to a database or other system.
  • Navigation controls
    Menus, tree views, and "bread crumb trails" are provided by this class of control.
  • Web part controls
    These controls let the user of a system "personalize" a web page. Usually, these controls can be used on highly sophisticated pages like My.MSN.Com.

©2013 About.com. All rights reserved.