Web sites are an integral part of today’s society and many companies (and individuals) rely on the Internet to carry out their day-to-day business. These web sites are increasingly becoming based on dynamic data posing a problem for programmers – does this mean that they will have to learn new languages in order to make their own dynamic web pages?
The simple answer is no. Provided, that is, if they are starting to use ASP.NET. The main advantage to using ASP.NET is that it is a framework rather than a specific programming language. This means a programmer can work with ASP.NET regardless of their background. So, for example, a C++ programmer can quickly move into ASP.NET development as can a Visual Basic programmer. They can even easily work on the same projects and web sites.
Of course, there are a couple of prerequisites to working with ASP.NET.
Preparing for Development with ASP.NET
In order to develop in ASP.NET a programmer needs two things:
- A web server
- The .NET framework
A key point here is, of course, that the web server must be one that supports the .NET framework. The web server can be something like:
- The Microsoft IIS (Internet Information Services) web server. This is a component of some versions of Windows such as XP Professional (although it is not installed by default)
- Apache 2 with mod_aspdotnet added on
Once the web server has been set up then the Microsoft .NET Framework needs to be installed. Like the web server this is available in different implementations, for example:
- From Microsoft ASP.NET Essential Downloads
- Mono (an open source, cross platform .NET development framework)
A programmer working with XP Professional can, therefore, be developing ASP.NET web pages after just a few minutes preparation. The next step is to open up a text editor and creating a simple ASP.NET web page.
A Simple ASP.NET Web Page
ASP.NET is not just a programming language - it is a programming framework. It is also a server application not a client application. And so the process for creating an ASP.NET web page is:
- Define the language to be used by the application. This is typically C# (C Sharp) or VB
- Create an HTML (HyperText Markup Language) form
- Send the form to the server
- Carry out any processing on the server
- Return any results (in HTML) to the client (the user’s web browser)
The first step is for the programmer to tell the server which language is to be used:
This should be the first line of the web page (and, in this case, informs the server that C# is to be used) and should be saved into a text file on the web server (for example C:\Inetpub\wwwroot\eac\Default.aspx). The next step is to define the components to be used:
Here a simple form has been created and each component has the property “runat” set to “server”. This informs the ASP.NET engine on the server that it must run the code. Next the web page needs the code to be run:
In this example one subroutine runs as soon as the web page loads but the other only runs when the button is clicked. It’s worth noting that the second subroutine must be assigned to the button as part of the page load (by creating an event handler). It’s also worth noting that these subroutines are invisible to the user. They will only see the results returned from the server.
Summary
An ASP.NET programmer needs two things:
- The Microsoft .NET framework
- A web server that supports the Microsoft .NET framework
With those in place the simplest ASP.NET web page can be created in a text editor and this web page will:
- Instruct the server to use a programming language (such as C# or VB)
- Contain a form with components. These must be defined as “runat=server”
- Define the subroutines that will on the server
The programmer can therefore quickly create a dynamic and useful web page with code that is invisible to the user but which makes full use of the capabilities of the server.