In Depth ASP.NET using ADO.NET

Introduction

In this article we will discuss a number of ways to retrieve, show, and update data with ASP.NET forms using ADO.NET. Also, we will have a clear idea about the most common server controls in ASP.NET. In particular, with this article we will cover ASP.NET server controls, ADO.NET DataSource, and creating Templated DataBound Controls, ASP.NET forms, using data with controls. We will review each of the proceeding server controls in detail. We will learn how to raise and handle some of the controls events, how to retrieve attributes from the control programmatically on the server, and finally we will demonstrate how to bind to control to a data source. Finally, we will have a complete example of retrieving, showing and updating by using server controls of ASP.NET.

Characteristically, when working with information or data from users we need to validate the data they provide us. For instance, if we have a field in our form where the user must enter his date of birth, we probably will want to control that user so that he enters a valid date. In this article we will not be validating the data collected, but we will use several server controls to handle data.

Construction Data with ASP.NET and ADO.NET

An ASP.NET server control derives directly or indirectly from System.Web.UI.Control. This base class belongs to the System.Web.UI namespace, which contains the elements common to all ASP.NET server controls. Three commonly used controls Page, UserControl, and LiteralControl are belong to System.Web.UI.Control developers generally do not instantiate Page or derive from Page. Page is important because every ASP.NET page is compiled to a Page control by the ASP.NET page framework,. Control developers also usually do not work with UserControl. User controls are developed using the same programming model as ASP.NET pages and are saved as .ascx text files. As it allows text to be encapsulated as a control, Control developers use LiteralControl widely.

IIS needs to be properly configured with FrontPage extensions for ASP.NET pages to execute. The required version of FrontPage extensions needs to be installed during the .NET SDK install or the Visual Studio .NET install. To verify this, open the Internet Information Services Manager and right-click the default Web site, and select Check Server Extensions from the All Task menu.

By extending an existing Web server control, by combining existing Web server controls, or by creating a control that derives from the base class System.Web.UI.WebControls.WebControl, we can develop a custom Web server control.

We will find typical scenarios in which we are likely to develop our own controls and provide links to other topics for further information in the following list.

  • We have created an ASP.NET page that provides a user interface that we want to reuse in another application. We would like to create a server control that encapsulates the user interface (UI) but we do not want to write additional code. ASP.NET allows us to save our page as a user control without writing a single additional line of code. For details, see Web Forms User Controls.
  • We would like to develop a compiled control that combines the functionality of two or more existing controls. For example, we need a control that encapsulates a button and a text box. We can do this using control composition, as described in Developing a Composite Control.
  • An existing ASP.NET server control almost meets our requirements but lacks some required features. We can customize an existing control by deriving from it and overriding its properties, methods, or events.
  • None of the existing ASP.NET server controls (or their combinations) meets our requirements. In that case, we can create a custom control by deriving from one of the base control classes. These classes provide all the plumbing needed by an ASP.NET server control, thus allowing us to focus on programming the features we need. To get started, see Developing Custom Controls: Key Concepts and Developing a Simple ASP.NET Server Control

Many custom controls include a combination of scenarios, where we combine custom controls that we have designed with existing ASP.NET server controls.

The ASP.NET server controls that provide a user interface are organized into two namespaces; System.Web.UI.HtmlControls and System.Web.UI.WebControls. While the Web server controls are richer and more abstract, the HTML server controls map directly to HTML elements.

Most Web server controls derive directly or indirectly from the base class System.Web.UI.WebControls.WebControl. On the other hand, the four controls in the upper-right corner (Literal, PlaceHolder, Repeater, and Xml) derive from System.Web.UI.Control. The controls on the left map to HTML elements. The controls in the center are for validating form input. Also the controls that are in the center provide rich functionality, such as the Calendar and the AdRotator controls. The controls which provide data binding support are on the right.

Before we start to talk about the server control, we will have some additional information about DataBound controls. Let's take a look at how we can develop a Templated DataBound control.

You might also like...

Comments

About the author

John Godel United States

John H. GODEL has an experience more than 22 years in the area of software development. He is a software engineer and architect. His interests include object-oriented and distributed computin...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson