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:
|
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.
|