When a page with the file extension of .aspx is requested, the web server (Internet Information Services, or IIS) will pass the request to the ASP.NET engine so that the HTML code that results from the process is sent back to the user agent (browser). At no time is ASP.NET code sent to the browser. The web browser only understands HMTL markup. Another important difference about an ASP.NET page is that the content should be within one HTML form element that is configured with the attribute and value of runat=“server”. In addition, the .aspx page can contain some additional ASP.NET specific markup such as directives at the top of the file, before the document declaration, or DOCTYPE. For example, you can optionally specify @ Page directive or other directives, web server controls, and server-side code.

Basic ASP.NET Web Page

Here is an example of a very basic ASP.NET web page. You will notice that the page mainly contains standard HTML elements. Keep in mind that this is a very simple example. There is quite a bit of markup missing if you are trying to ensure that the page would pass validation. For example, the DOCTYPE is missing, as well as other important HTML elements such as theelement.

Directives

In the basic example shown above, you will notice that the first line lists some specific ASP.NET syntax. This first line is known as a directive. When directives are used, they can be located anywhere in an .aspx or .ascx file. However, the standard practice is to include them at the beginning of the file. Each directive can contain one or more attributes that are specific to that directive. The most common directive is the Page directive, but as you continue to develop ASP.NET pages, you will become more familiar with others.

Directive Examples

@ Page, Language Attribute

In order to process the server-side code contained in the ASP.NET page, the server needs to know what language the code will be in. The first line in the example above instructs ASP.NET that at runtime it should be expecting C# code for that page. If your page contained VB.NET code, then the value of the language attribute should be set to VB. While you can have some pages in your web application defined for C# and others for VB, you are not able to have both C# and VB code within the same page. Do not worry too much about Directives or their syntax at this moment. Fortunately, Visual Studio automatically inserts many of these page directives when you perform certain actions such as adding a new .aspx file.