Ive been getting back into asp.net web forms and I had a question about the controls.
When I add a control declaratively (ie by dragging and drop a control from the toolbox), for instance a button onto an aspx page, what I expected to occur was for a button object to be declared and instantiated in the designer.cs file
Instead all I can find is
protected global::System.Web.UI.WebControls.Button ButtonTest;
but nowhere can I find the code that created a new button object and assigns it to ButtonTest. Does anybody know where/when this occurs?
It used to work along the lines you describe, back in .NET 1.1 days. The introduction of partial classes allowed that approach to be simplified, so you normally don’t have to directly interact with the generated code.
If you’d like to see exactly what the framework is doing: the markup gets compiled into a partial class, which contains the declarations for the objects on the page, along with calls to constructors, etc.
You can’t easily view the auto-generated code from Visual Studio. To see it, enable debugging for your project and look in:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\
The source code for the compiled file should be in one of the subdirectories there.
Even easier, if you create a small compilation error in your page, then try to view it in a browser, you should see a link at the bottom of the error page that lets you view the “compilation source.”