Page class in ASP.NET

  • Thread starter Thread starter ozie
  • Start date Start date
O

ozie

Hi ,
I am new to ASP.NET. I was reading about Page class in one
of the ASP.NET books and am confused with the way the Page
class is actually implemented.What is didnt understand in
when is this Page class created ? Is it when the ASPX file
is requested for the first time ? Is this executable Page
object saved somewhere in the server hard disk space or is
it available only in the memory ? I would really like to
know more about how all this is implemented in ASP.NET.So
if you know the answers to these or you have links to any
pages which could be of any help please do let me know.

Thanx in advance,

Cheers.........
 
when is this Page class created ? Is it when the ASPX file
is requested for the first time ?

The Page class is created at design time by the developer. It is
instantiated at run-time, with the first request for the Page, and cached in
memory, so that future requests for the Page don't have to re-instantiate
it. Of course, the Page can expire from the cache (after a period of no
requests for it), in which case it is re-instantiated with the next request.
Is this executable Page
object saved somewhere in the server hard disk space or is
it available only in the memory ?

A class is an in-memory object. In special circumstances, classes can be
serialized and stored in other media, but this is not typical.
if you know the answers to these or you have links to any
pages which could be of any help please do let me know.

You can get the entire .Net SDK for free from Microsoft at the following
URL:

http://www.microsoft.com/downloads/...A6-3647-4070-9F41-A333C6B9181D&displaylang=en

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.
 
Kevin Spencer said:
The Page class is created at design time by the developer. It is
instantiated at run-time, with the first request for the Page, and cached in
memory, so that future requests for the Page don't have to re-instantiate
it. Of course, the Page can expire from the cache (after a period of no
requests for it), in which case it is re-instantiated with the next
request.

Actually, Kevin, it's more complicated than this.

When you create a .aspx page, you are creating an anonymous class which
derives from System.Web.UI.Page. If you are using codebehind, you're
creating a named class which derives from Page, and the anonymous class
derives from the names class.

An instance of the class is created for each request to that page. The
methods and events of the class are executed in a well-defined order, and
the resultant HTML (or other data) is sent back to the client. At the end of
the request, the instance of the class is destroyed.

ASP.NET may cache the output of the page. When a request comes in for a
cached page, the output is sent to the client and another instance of the
class is _not_ created.
 
John,

What is the names class? can't find it
What is a named class? vs. un-named class? if any exist?
 
MS News (MS ILM) said:
John,

What is the names class? can't find it
What is a named class? vs. un-named class? if any exist?

When using codebehind, you might have the following situation for
~/default.aspx.

In file default.aspx:

<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false"
Inherits="Webproject1.default" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>default</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="default" method="post" runat="server">
<asp:Button id="Button1" runat="server" text="Button"
onclick="Button1_ClickHandler" />
</form>
</body>
</HTML>

In file default.aspx.cs:

namespace Webproject1
{
public class default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
...
protected void Button1_ClickHandler(object sender, System.EventArgs
e)
{
// Do something because the button was clicked
Button1.Text = "Clicked!";
}
}
}

All the codebehind classes of the web project are compiled together to
produce a single assembly, in this case, bin\Webproject1.dll. When
default.aspx is requested, ASP.NET parses it and compiles it into what I
called an "anonymous" class. Actually, it uses a name like ASPX_default.
This class is declared like:

public class ASPX_default : Webproject1.default
{
}

because of the "Inherits" clause in the Page directive.

So the "anonymous" class inherits the "named" class (Webproject1.default)
from Webproject1.dll, which in turn inherits System.Web.UI.Page from
System.Web.dll.

On a request, an instance of class ASPX_default is created. Various methods
of this class and of its base classes (especially, of the Page class) are
executed during the lifetime of the request, and the final output is sent to
the client. When all that's done, the instance of ASPX_default is destroyed.
The next time the page is requested, a new instance of the ASPX_default
class will be created. If the page has been cached, then the cached output
will be sent and no new instance will be created.
 
Back
Top