Monday, October 22, 2007

Choosing a Page Model::::::::::::::::::

The single-file and code-behind page models are functionally the same. At run time, the models execute the same way, and there is no performance difference between them. Choosing a page model therefore depends on other factors, such as how you want to organize the code in your application, whether it is important to separate page design from coding, and so on.

Advantages of Single-File Pages
As a rule, the single-file model is suitable for pages in which the code consists primarily of event handlers for the controls on the page.

Advantages of the single-file page model include the following:
In pages where there is not very much code, the convenience of keeping the code and markup in the same file can outweigh other advantages of the code-behind model. For example, it can be easier to study a single-file page because you can see the code and the markup in one place.


Pages written using the single-file model are slightly easier to deploy or to send to another programmer because there is only one file.

Because there is no dependency between files, a single-file page is easier to rename.

Managing files in a source code control system is slightly easier, because the page is self-contained in a single file.

Advantages of Code-Behind PagesCode-behind pages offer advantages that make them suitable for Web applications with significant code or in which multiple developers are creating a Web site.

Advantages of the code-behind model include the following:

Code-behind pages offer a clean separation of the markup (user interface) and code. It is practical to have a designer working on the markup while a programmer writes code.

Code is not exposed to page designers or others who are working only with the page markup.

Code can be reused for multiple pages.

Compilation and Deployment
Compilation and deployment of both single-file and code-behind pages is similar. At its simplest, you copy the page to the target server. If you are working with code-behind pages, you copy both the .aspx page and the code file. When the page is first requested, ASP.NET compiles the page and runs it. Note that in both scenarios you deploy source code with the markup.

Alternatively, you can precompile your Web site. In that case, ASP.NET produces object code for your pages that you can copy to the target server. Precompilation works for both single-file and code-behind models, and the output is the same for both models.

No comments: