Friday, January 23, 2015

How ASP.Net controls are connected to code behind class variables

- The Page class from the .Net library provide some basic functionality that allow web page to host other controls, and render itself to HTML.

- The code behind file is inherited from the Page class of .Net library to acquire the basic asp.net web page functionality.

- When you compile your code the ASP.NET automatically merge some extra code to your code behind class. This automatically generated code defines all control from the web page as the protected variables to your code behind class, so that you can access them in your code behind class.

- The ASP.NET compiler create one more extra class to represent the actual .aspx page. This class inherits from the your custom code behind class. ASP.NET add _aspx to the name of code behind class to name this extra class for example (theCodeBehindClass_aspx). This class contains the code needed to initialize the page and its controls and this is the class that ASP.NET instantiates when it receives the page request.
All the controls in the code behind class are protected because of the way of inheritance implemented in .Net library for Page class. The protected variable act like the private variables and the protected variables ensure that they can only be accessed from the derived page classes. So, this is the way how ASP.Net match the control variables to their respective control tags and attach event handlers at run time.

No comments:

Post a Comment