Download the C# source used in this article.
Download the VB.NET source in this article.
In classic ASP, our code was a mix of in-line scripts and HTML. It was very easy for anyone, with logical thinking, to write the code for a dynamic web page. The reason was simple – the steps of the code that was ran was from top to bottom. Wherever there was HTML, it outputted the HTML. When the page parser found a script block, it would then translate it into a small program/applet and then it would be executed. If any output was required from these script blocks, it was a matter of using the Response.Write method. As ASP developers got familiar with their technology, they wanted to reuse repetitive code and scale out their application. There was workarounds such as having common file includes with methods and functions but did not address a true scalable solution. There was the ability to create server/ActiveX components but this was only an option to the people who were not on shared hosting plans or for the people with hosts that did allowed the installation of the components for a fee.
This area is where ASP.NET excels in over its predesor. Server controls is the answer to a scalable design and reusable code for outputting common user interfaces. Microsoft ships with built-in server controls that will do almost any general task from input fields, to buttons, to displaying data in a table (DataGrid). Likewise, with classic ASP, as time progresses and as your knowledge of the .NET framework begins to mature, you will start to demand more control of those server controls from doing repetitive tasks such as data binding.
Fortunately, we are not stuck completely as we found ourselves in classic ASP. We are able to extend the built-in server controls at a very easy level and with a great deal of comfort. We can achieve this by inheriting from the server control that we want to extend its functionality or to change the behaviour of. Furthermore, we can create a whole new server control for new functionality and interaction that could not be provided by the built-in server controls.
Over a series of articles, I will be writing about different aspects of creating server controls for ASP.NET - the articles will span over a few months. This article series is not aimed for beginners but is aimed for intermediate programmers and beyond. As far as this article is concerned, we will be dealing with: