Code Model


ASP.NET pages consist of two parts : the definition of the user interface using static text and server controls, and the implementation of the user interface behavior and the Web application logic in the form of server-side code.

ASP.NET provides a new code model that enables both page developers and development tools to cleanly and easily separate code from presentation. This feature is a significant improvement over Active Server Pages, which required code to be interspersed with the static content of the page. The ASP.NET code model enables easier division of labor among a team of developers and designers, and it increases the readability and maintainability of both code and content. This new code model is commonly used in one of two forms. The first form involves simply embedding code in a runat ="server" script block within the .aspx file itself, as you saw in Listing 2-1. This form is sometimes referred to as inline code . The second form involves implementing a class deriving from Page , saving the code in a separate file, and associating it with the .aspx file via the Page directive. This form is generally referred to as code-behind .

In this book, we will use the inline code model for most examples, primarily because it is easier to illustrate concepts with and it is easier to develop by using only the standard tools available with the .NET Framework SDK. The second approach ”implementing code in a separate file ”is the model favored by Visual Studio .NET because it enables editing of the code using the standard Visual Studio .NET code editor. The two models are functionally equivalent and produce the same output at run time. But, for our purposes, what's most important is that the custom controls function identically in both models.

The code model in ASP.NET is also language agnostic , as is the programming model associated with any other application built using the .NET Framework. You can use any .NET programming language ”such as C#, Visual Basic .NET, Microsoft Visual J#, and Microsoft JScript .NET ”to implement the behavior and logic of the page. You specify the code language of the page using the Language attribute of the Page directive. If you are using the inline code model, a single application might have pages implemented in multiple languages, which work together seamlessly. Each page can use only a single language. However, in the code-behind model used by Visual Studio .NET, all the code-behind class files are precompiled into a single assembly at design time and therefore must be implemented in the same language.



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net