I’m writing a formbuilder for our CMS which dynamically loads bespoke controls into panels within a repeater.
The bespoke controls all inherit from, lets say 5arx.FormBuilder.FormControl, a base class which defines abstract methods for initialising, validating, repopulating, gathering submitted data from them. Controls range from simple text fields to complex, composite client-side controls.
It all works very well, but I’ve noticed something I feel is anomalous. During the course of writing code to retrieve form controls. gather their data and persist it to my database I noticed that their type reverts to the way objects get typed if you write your code in the (v. irritating) VS ‘website project’ mode.
So, for example a control that is defined as living in a namespace and being of type
5arx.FormBuilder.FormControl.MyBespokeControl
Sarx.FormBuilder.FormControl.MyBespokeControl
at runtime reports its type (via simple call to GetType()) as being of type:
ASP.5arx_FormBuilder_FormControl_MyBespokeControl
ASP.Sarx_FormBuilder_FormControl_MyBespokeControl
Getting the BaseType property will correctly retrieve the underlying class, but it is perplexing to me why this should be happening. Particularly as I spent much of the summer refactoring our app from its original form as VS Website project (complete with shared code in the App_Code folder and other nastiness) to the (IHMO) correct web application project + supporting claass libraries so that we would have control over our namespaces and not get everything compiled into the ASP.x namespace 🙁
I would really appreciate some explanation/clarity.
EDIT: Modified the (hypothetical) example root namespace.
Apparently this is to allow the ASPX files to be updated and recompiled independently of your code-behind. Basically the actual control/page type is derived from the type which you write in code.
See this article (from 2006 but still apparently relevant 🙂 for a lot more details.
I can’t say I know a lot about ASP.NET, but based on the article it looks like this is independent of whether or not it’s a “website” project. My guess is that any time you’ve got a
template-style XML file (aspx, ascx etc), the ASP.NET runtime compiler will do all of this for you.
Whether or not it will happen if you precompile the site, I don’t know.