ASP.NET Web Forms

Web Form Events

From the moment a user first requests an ASP.NET Web Form to the moment the server actually sends the response, quite a few events and processes occur. A few of the most important ones are described in the following sections.

A significant number of events occur between the moment a client issues a page request and the moment that the server sends the response. Many of these events will be transparent to you as the developer, and they will involve the compiler, the preprocessors, and the various collections that make up the .NET framework. However, you will need to understand some events because you will likely come across them in your coding escapades. Figure 3.1 shows the events in a life cycle of an ASP.NET request.



Figure 3.1
The life cycle of an ASP.NET request

 

Page Directives

Page directives enable you to set optional metasettings for the compiler when it processes the ASP.NET Web form. You can use page directives to set the default language for the ASP.NET Web form, enable or disable session state, choose to buffer the contents of the page before sending to the client, and make a host of other changes.

Page directives must be located at the very top of an ASP.NET Web Form, before any other code. A page directive is always contained inside <% %> tags and always begins with the @ character. Here is an example of the syntax used for a page directive:

<%@ directive.property = value %>

For example, to turn off session state for a page, you use the following page directive:

<%@ Page EnableSessionState="false"%>

Server-Side Includes

SSIs offer a way to insert the contents of a file into an ASP.NET Web form. Because an SSI is inserted before the page is compiled to IL, you can use an SSI to insert blocks of source code into a page. You can use SSIs to add a copyright notice to the bottom of a page, include a common set of functions, or include any other sort of static content.

The code for an SSI looks like this:

<!-- #include PathType = FileName -->

PathType can be set to either File or Virtual, depending on the type of path being referenced:

  • File sets a relative path from the directory in which the ASP.NET Web Form is located. It is important to note that the file location cannot be in a directory higher on the file tree than the current directory. This prevents a possible breach in a site's security.

  • Virtual enables you to include a file from a virtual path from a virtual directory on the Web server.

Tip
You should not use SSIs to encapsulate site functionality such as site navigation or common site text. ASP.NET offers a solution for these types of situations, called user controls, which are explored in the following section.

 

You might also like...

Comments

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.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan