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.
Comments
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
thanks
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?
www.virtualgoldfarb.com/samples/NewMigration2.zip
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.
Thanks.
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.
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.
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.
Thanks,
Peter
Thanks
Gurvinder
Great article by the way!
Ryan
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
Thanks in advance,
Jingyoo.
I chose multiple files.