OdeToCode IC Logo

Code-Behind or Single File?

Thursday, June 2, 2005

The latest OdeToCode article: The Code Models Of ASP.NET 2.0.

The obvious question is which model should you be using for your ASP.NET projects? The answer will largely depend on the type of person you are. Working from a single file containing both the code and ASPX markup will appeal to many people, while others will insist on a strict separation and favor the code-behind model. The single-file model has an advantage in configuration management and deployment, since there is only a single file to version and deploy. Intellisense and refactoring tools appear to work equally well with both models, so there will be no clear winner in the productivity category. One additional factor in deciding on the model to use is your pre-compilation strategy, which will be the topic of our next article...

I have some more thoughts on the subject to blog later this week, as there are some subtle but suprising differences, particularly in VB.NET versus C# land....

Teaser, teaser, teaser. It's all about the teasers.

Kilambi Tuesday, August 9, 2005

When I converted ASP to ASP.NET using the Migration Tool(Microsoft) I get only a single file. Here in the file I need to call a WebService and use the dataset to populate the fields in the page. Do you have any solutions for this. I need all the code behind in a single aspx file

scott Tuesday, August 9, 2005
Hi Kilambi:

What is the error or problem you are seeing. You say there is only a single file, but I don't see in the description of the problem what you are missing, exactly.

Have you tried the latest migration tool?

RM Tuesday, November 8, 2005
Hi, great article.. just wondering how you best approach c# event handlers with the new partial classes.

Is there an easy way to add events to controls in the aspx page? e.g. for a repeater databound event do you need to just have to manually call a method Repeater1_DataBound(..) In VS2003 i would typically go into the auto-generated code section and use the intellisense to add the new method for me using the tab key. This functionality is still there - but obviously there is no longer any auto-generated section.

scott Friday, November 11, 2005
I wouldn't manually call the method.

If you are using a single file (no CodeFile or code-behind), the easiest method is probably to use the drop down lists above the editing window to add event handlers.

If you are in a CodeFile, you can always override FrameworkInitialize just like in 1.1 and add the event handlers with += and TAB completion. This approach works with or without CodeFile.

Then of course you can always double click on an event in the Properties window for a control. That will wire things up and add a declaration for you.
mj Tuesday, November 22, 2005
Nice artile. Thanks!

I think one of the things to think through is how you are going to deploy your application and versioning (upgrading). I'm not sure that I like the idea of having the soure code deployed with the application so that the "runtime" can compile it.

I'm wondering if this means that you could modify the source and copy the source file to the web application directory and the compiler will "recompile" that page and also the app .dll? -- kind of like old .asp pages :)

I'm sure there are some other considerations for using partial classes...I'll need to dig a little deeper.

scott Wednesday, November 23, 2005
mj: Yes. You can put everything on the server and ASP.NET will recompile it all.
Peter B Wednesday, January 25, 2006

I want to add my own namespace instead of letting .NET put my page under the ASP namespace.

Is there someway to do this? I haven't been able to find a property, etc, to override the default namespace assignment. For the record, I think this is kinda nutty.

Is there any documentation you can refer me to to help me understand why MS chose to implement Web pages, and to a lesser extent custom classes with no default support for namespaces, and the rationale behind the default class naming?

This is the complete opposite of winforms, and it will more than likely cause some problems with code reuse, with respect to BO's, from one technology to the other.

Gurvinder Thursday, February 16, 2006
Can u please explain with correct example for autowireup directive in true or false case.

Ryan Friday, June 16, 2006
I have an application that uses the single page model, but I cant get the intellisense to work. Is there a setting in vs 2005 that makes all pages single model? Also, can I double click a for object and it create the event handler automatically in the single page model? Thanks for any help in advance!

Great article by the way!

jingyoo Thursday, June 22, 2006
I have read your article through asp.net site. I appreciate it, and can i have a question?
You show me an excerpt of the file generated by parsing the ASPX, but i can't find it.
How can i view this code?

Thanks in advance,
Jingyoo han Thursday, June 22, 2006
Please tell me how to view the source code in Temporary asp.net files directory.

Thanks in advance,

scott Thursday, June 22, 2006
Jingyoo: Set debug="true" in web.config and you'll find the files in the temporary asp.net files directory.
Gravatar Paul Tuesday, February 2, 2010
thanks for the site. very informative. helped a lot.
I chose multiple files.
Gravatar Geo Mathew Tuesday, January 11, 2011
Thanks for this article. One doubt exists. When I changed the Partial to Public for Default class in a, ASP.NET web project, Still in the dll I can see some new members add to the default class. How this happened, because in the default class defination I didnt add any code for that and the class is public
Comments are closed.