Getting Started with ASP.NET Programming

How to Prepare for ASP.NET Development in Windows

© Mark Alexander Bain

Apr 21, 2009
Starting to Program with ASP.NET, Mark Alexander Bain
A new ASP.NET developer just needs two things: a web server and the .NET framework. With those they can quickly produce a simple ASP.NET web page.

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:

<%@ Page Language="C#" %>

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:

<form method="post" runat="server">
<input type="submit" id="Button_AE" runat="server">
<div id="AE_Text" runat="server"></div>
</form>

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:

<script runat="server">
private void Page_Load(object sender, EventArgs e) {
Response.Write("<h1>Environmental Archaeology Consultancy</h2>");
Button_AE.Value = "What is environmental archaeology?";
Button_AE.ServerClick += new EventHandler(Click_Button_AE);
}
private void Click_Button_AE (object sender, EventArgs e) {
AE_Text.InnerHtml = "Environmental archaeology is "
+ "the study of human interaction with the environment "
+ "in the past through archaeology<sup>1</sup><br><br><br>"
+ "<sup>1</sup>Association for Environmental Archaeology";
}
</script>

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.


The copyright of the article Getting Started with ASP.NET Programming in ASP Programming is owned by Mark Alexander Bain. Permission to republish Getting Started with ASP.NET Programming in print or online must be granted by the author in writing.


Starting to Program with ASP.NET, Mark Alexander Bain
The Code for an ASP.NET Web Page, Mark Alexander Bain
An HTML Form, Mark Alexander Bain
The Processed ASP.NET Web Page, Mark Alexander Bain
 


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo