Sunday, August 24, 2008

Why is a variable which represents a Web control declared as protected in ASP.NET?

'Cause ASP.NET uses inheritance in web-page model.

Example I have a ASP.NET page named A.aspx, which has a code-behind file named A.aspx.cs. Class A inherits a basic set of functionality from Page class. When class A is compiled, it will be merged with some extra code (with control declarations) automatically. Then the ASP.NET compiler wil create one more class for the actuall .aspx page. This class inherits from your custom code-behind class.

No comments: