Article
Beginning ASP.NET Using VB.NET - Chapter 14: ASP.NET Server Controls
By Wrox Press
November 16th, 2001
Reader Rating: 8.5
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Next
By now, you should be fairly comfortable with the object-oriented approach used by the .NET Framework to create ASPX pages. If not, see Sample Chapter 1, "Getting Started with ASP.NET". You gained some experience (in Chapter 3) of using ASP.NET server controls (also known as web controls). This chapter will continue the discussion of ASP.NET server controls and provide numerous details and samples illustrating their usage. HTML server controls and User controls are not covered in this chapter. Throughout this chapter, the phrase "ASP.NET server controls" will refer to that specific group of controls derived from the System.Web.UI.WebControls base class, which includes, for example, <asp:button>, <asp:textbox>, <asp:listbox>, and <asp:datagrid>.
ASP.NET server controls are reusable components that can perform the same work as traditional HTML controls, but have the additional benefit of being "programmable objects". In other words, they can be programmatically accessed, just like any other .NET object or class, respond to events, get/set properties, and do all the other things objects do. ASP.NET server controls use a tag-like syntax for declaring the various controls used on a web page -- for example:
<asp:button id="SampleButton" runat="server" text="I'm A Sample Button!"/>
One of the unique qualities of ASP.NET server controls is that, even though their tag syntax is different from HTML's, every ASP.NET server control is rendered to standard HTML after being processed on the server, thus abstracting the functionality of the entire HTML control set. Additional ASP.NET server controls, provide the ability to render rich web content -- for example, a Calendar control for displaying dates, a DataGrid control for displaying data, as well as other controls, which we will explore throughout this chapter.
Here's a summary of the topics we will cover in this chapter:
- A review of the syntax and benefits of ASP.NET server controls
- A brief recap of the System.Web.UI.Page lifecycle
- Using a variety of ASP.NET server controls on a web form.
- Using validation controls -- you'll learn some techniques for validating user input in a web form
- Introducing data rendering controls -- a brief introduction to this very powerful group of controls for displaying data
- Presenting a complete application that allows you to incorporate your own schedule of events within the context of an ASP.NET calendar control
In the past, the way we would create a web page might vary, but it would almost always involve the embedding of various HTML tags in our pages -- perhaps some client-side scripting to handle event processing, or validate form input, and some text to make up the overall content of the page. Additionally, the advanced developer would often be required to write pages in a manner that supported a variety of browser types and capabilities, thus mixing in special-case code, and even client-side validation, which added an additional layer of development complexity that was often difficult to maintain.
In this chapter, we're going explore ASP.NET server controls in detail -- specifically, what they are, how to create them, and how to programmatically manipulate them within ASP.NET web forms (ASPX files). We will explore the various types of ASP.NET server controls, which can be broken down into four broad categories:
- Intrinsic controls -- these controls correspond to their HTML counterparts, or simulate one if none exists. Examples include the Button, ListBox, and TextBox controls.
- Data-centric controls -- controls used for binding and displaying data from a data source, such as the DataGrid control.
- Rich controls -- these controls have no direct HTML counterparts. Rich controls, like the Calendar control, are made up of multiple components, and the HTML generated will typically consist of numerous HTML tags (as well as client-side script), to render the control in the browser.
- Validation controls -- like, for example, the RequiredFieldValidator, which can be used to ensure proper data input within a web form.
By the end of this chapter, you will be able to create your own web forms that utilize a variety of the ASP.NET server controls available. You will be exposed to the variety of ASP.NET control properties available to you as a web developer, which can be used to tailor the look or functionality of the various controls. You will also learn to write event handlers for the various events raised by ASP.NET server controls.
Other Types Of Controls
The thrust of this chapter is primarily to describe and demonstrate the various aspects of ASP.NET server controls. There are, however, two additional types of controls that you should be aware of:
- HTML Server Controls
- User Controls