Sideway from Sideway
Draft for Information Only


 ASP.NET Page Class Overview
 Generating and Running the Page Class Code
 Single-File Pages
 Code-Behind Pages
 See Also
 Sources and References


ASP.NET Page Class Overview

When an ASP.NET page is requested and renders markup to a browser, the code that runs is not solely the code that you created for your page. Instead, at run time, ASP.NET generates and compiles one or more classes that actually perform the tasks required to run the page. This topic provides an overview of the code that is generated at run time.

Generating and Running the Page Class Code

An ASP.NET page runs as a unit, combining the server-side elements in a page, such as controls, with the event-handling code you have written. You do not have to precompile pages into assemblies. ASP.NET dynamically compiles pages and runs them the first time they are requested by a user. If there are any changes to the page or resources the page depends on, the page is automatically recompiled. The class or classes that the compiler creates depends on whether the page uses the single-file model or the code-behind model.
ASP.NET also supports precompilation of a Web site to enhance performance and perform error checking as well as to support site deployment. For more information, see ASP.NET Web Site Precompilation Overview. Precompilation works for both single-file and code-behind page models, and the compiler output is the same for both models.

Single-File Pages

In a single-file page, the markup, server-side elements, and event-handling code are all in a single .aspx file. When the page is compiled, the compiler generates and compiles a new class that derives from the base Page class or a custom base class defined with the Inherits attribute of the @ Page directive. For example, if you create a new ASP.NET Web page named SamplePage1 in your application's root directory then a new class named ASP.SamplePage1_aspx is derived from the Page class. For pages inside of application subfolders, the subfolder name is used as part of the generated class. The generated class contains declarations for the controls in the .aspx page and contains your event handlers and other custom code.
After page generation, the generated class is compiled into an assembly, the assembly is loaded into the application domain, and then the page class is instantiated and executed to render output to the browser. If you make changes to the page that would affect the generated class—whether by adding controls or modifying your code—the compiled class code is invalidated and a new class is generated. For more information on compilation in ASP.NET, see ASP.NET Compilation Overview.
The following illustration shows the inheritance model for the page class in a single-file ASP.NET Web page: image

Code-Behind Pages

In the code-behind model, the page's markup and server-side elements, including control declarations, are in an .aspx file, while your page code is in a separate code file. The code file contains a partial class—that is, a class declaration with the keyword partial (Partial in Visual Basic) indicating that it contains only some of the total code that makes up the full class for the page. In the partial class, you add the code that your application requires for the page. This typically consists of event handlers, but can include any methods or properties that you need.
The inheritance model for code-behind pages is slightly more complex than that for single-file pages. The model is this:
  1. The code-behind file contains a partial class that inherits from a base page class. The base page class can be the Page class, or it can be another class that derives from Page.
  2. The .aspx file contains an Inherits attribute in the @ Page directive that points to the code-behind partial class.
  3. When the page is compiled, ASP.NET generates a partial class based on the .aspx file; this class is a partial class of the code-behind class file. The generated partial class file contains declarations for the page's controls. This partial class enables your code-behind file to be used as part of a complete class without requiring you to declare the controls explicitly.
  4. Finally, ASP.NET generates another class that inherits from the class generated in Step 3. This second generated class contains the code required to build the page. The second generated class and the code-behind class are compiled into an assembly that runs to render output to the browser.
The following illustration shows the inheritance model for the page class in a code-behind ASP.NET Web page: image

See Also


ASP.NET Web Page Code Model

Sources and References



ID: 211000008 Last Updated: 10/8/2021 Revision: 0 Ref:



  1. Active Server Pages,  ,
  2. ASP Overview,  ,
  3. ASP Best Practices,  ,
  4. ASP Built-in Objects,  ,
  5. Response Object,  ,
  6. Request Object,  ,
  7. Server Object (IIS),  ,
  8. Application Object (IIS),  ,
  9. Session Object (IIS),  ,
  10. ASPError Object,  ,
  11. ObjectContext Object (IIS),  ,
  12. Debugging Global.asa Files,  ,
  13. How to: Debug Global.asa files,  ,
  14. Calling COM Components from ASP Pages,  ,
  15. IIS ASP Scripting Reference,  ,
  16. ASP Keywords,  ,
  17. Creating Simple ASP Pages,  ,
  18. Including Files in ASP Applications,  ,
  19. ASP Overview,  ,
  20. FileSystemObject Object,  ,
  21.,  , ADO Object Model
  22. ADO Fundamentals,  ,

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna

Home 5






Hobbies 8


Chinese 1097

English 339

Reference 79


Hardware 224


Application 213

Digitization 32

Latex 52

Manim 204

KB 1

Numeric 19


Web 289

Unicode 504


CSS 65

SVG 46


OS 429

DeskTop 7

Python 72



Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 33

Coordinate Geometry 2

Calculus 67

Complex Analysis 21


Tables 8


Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5


Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1

Copyright © 2000-2022 Sideway . All rights reserved Disclaimers last modified on 06 September 2019