Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET what is the meaning of AutoEventWireup and Inherits?

Tags:

asp.net

Given the following statement,

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="XXX.aspx.cs" Inherits="XXX" %>
  1. What is the meaning of AutoEventWireup?
  2. What if the value of AutoEventWireup is equal to false
  3. What is the meaning of XXX in the Inherits attribute?
  4. I cannot find the definition of XXX in the auto-created file in ASP.NET 2008. Where is the XXX defined?

Thank you

like image 831
q0987 Avatar asked Sep 15 '10 17:09

q0987


1 Answers

AutoEventWireup = false means that your Page_Load event will not be automatically hooked to the page's Load event and so on for PreRender and the other page lifecycle events. It means in the constructor of your code-behind base class for the Page, you will have to manually do

Load += new ..EventHandler(Page_Load) etc

Inherits tells the page which class is the base class for the class that the runtime will generate when your application starts up. The auto-generated class will be in the ASP namespace and be put in the Temporary ASP.NET Files and will inherit from your class. This is how protected properties and event declarations in your code-behind can actually serve as handlers that are specified in the declarative .aspx markup

XXX is usually side-by-side right next to the aspx file and is the same name as the aspx file, unless it is Default, in which case that is a C# keyword, so sometimes it uses _default as the class name while the page itself is Default.aspx.

You should probably try to read some tutorials on ASP.NET page inheritance, here is an example, but you should search for more:

http://west-wind.com/weblog/posts/3016.aspx

like image 72
David Avatar answered Oct 13 '22 00:10

David