Migrating from ASP to ASP.NET - Server Controls
(Page 6 of 11 )
Seemingly simple tasks such as adding dynamic data from a database to a drop-down list or table can require that a lot of code be written in ASP. Fortunately, much of this coding is eliminated in ASP.NET through using new “controls” referred to as Server Controls. Server Controls are pieces of code supplied by Microsoft or other third parties that are capable of generating browser specific HTML. A list of commonly used ASP.NET Server Controls is shown below (many other controls exist):
- DropDownList – Creates an HTML <select> tag with <option> tags.
- DataGrid – Creates a fully pageable, editable, and selectable table of data using the HTML <table> tag.
- Calendar – Creates HTML for a calendar using a <table> tag.
- Button – Creates an HTML <input> tag that is capable of raising “events”.
- TextBox – Creates standard, password, or multi-line textboxes using the <input> and <textarea> HTML tags.
To show how powerful server controls are, let’s take a quick look at how easy it is to create a monthly calendar using ASP.NET’s Calendar control. Figure 3 shows the code you need to add into an ASP.NET page (named Calendar.aspx) to create a basic calendar. Figure 4 shows the result that is generated when the ASP.NET page is called.
<html>
<body bgcolor="#ffffff">
<h2>ASP.NET Calendar Control</h2>
<form runat="server">
<asp:calendar id="calMonths"
runat="server" />
</form>
</body>
</html>
Figure 3. The Calendar control is capable of generating fully functioning calendars with minimal effort on the developer’s part. If you’ve ever had to write a calendar for ASP applications, you’ll appreciate how much time is saved by using the ASP.NET Calendar control.
Figure 4. The ASP.NET Calendar control makes creating calendars a snap. Although not shown, events, meetings, and other data can be added to the calendar without writing a lot of code. The calendar’s look and feel can also be customized.
All ASP.NET Server Controls start with the “asp” prefix and are followed by the name of the control. Although the “id” attribute is optional it is recommended since it can be used to identify the control programmatically. The runat=”server” attribute and associated
value is required. Server Controls such as the Calendar control simplify coding and allow relational, XML, or other data to be associated with the control using .NET languages such as C# or VB.NET.
Next: User Controls >>
More ASP.NET Articles
More By Dada Kalander