Sideway
output.to from Sideway
Draft for Information Only

Content

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

ASP.NET Page

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

Concepts

ASP.NET Web Page Code Model

Sources and References

  • https://docs.microsoft.com/en-us/previous-versions/aspnet/ms178138(v=vs.100)
  • https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.page?view=netframework-4.8

©sideway

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

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 337

Reference 68

Computer

Hardware 154

Software

Application 207

Digitization 25

Latex 35

Manim 203

Numeric 19

Programming

Web 285

Unicode 504

HTML 65

CSS 63

SVG 9

ASP.NET 240

OS 422

DeskTop 7

Python 64

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 32

Coordinate Geometry 1

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


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