If you have done some Web programming in the past, you may have had to link together HTML pages, client-side scripts, and CGI scripts. Writing Web applications can be difficult, because you are often constrained in what you can do.
With HTML, you may have to resort to intricate coding and text and symbol positioning to get the look you want. Client-side scripts can be limited in their abilities to protect a user from intrusive script operations.
The bottom line is that you may often wind up dealing with multiple levels of complexity in order to write a Web application.
ASP has features and functionality that can cut down some of this complexity.
By the end of this module, you will be able to:
- Describe the setup and operation of a Web application through ASP
- Specify application start and end procedures in the Global.asa file
- Describe uses for application variables with multiple users
- Explain how application variables may be incorrectly updated
- Read and Write text files with ASP
- Create a file with ASP that can be read by a user application
The next lesson describes how you set up and run a Web application through ASP.
With the .NET framework, Microsoft also has significantly changed the preferred way for supporting client-side scripting of Web browsers. As an alternative to directly writing script for conventional HTMLpages, ASP.NET has been enhanced to automatically generate client-side script
as required for most common client-side scripting tasks. In particular, ASP.NET takes care of customizing clientside
scripts for kind and version of Web browser being used to access ASP pages. This promises to save Web developers
time and effort, though of course there will still be times when programmers will want to write their own explicit client-side scripts.
ASP.NET accomplishes automatic client-side script generation as needed through its implementation of
ASP.NET Server Controls
These controls reside in the System.Web.UI.HTMLControls and System.Web.UI. WebControls namespaces. Items in the HTML controls collection correspond to HTML elements but are augmented with additional features, and functionality (e.g., form <input> elements can be configured to automatically retain user modified values during self-referencing calls to the ASP.NET page). Items in theWeb controls collection
include user interface classes analogous to traditional Visual Basic classes (e.g., the text box class, which is at once analogous to the Visual Basic text box class and to HTML <input> elements of type text). The Web controls collection also contains classes of advanced functionality, data bound controls (DataGrid, DataList, Repeater), a calendar control, an ad rotator control, and several form validation controls (CompareValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator).
Validation controls in particular tend to generate client-side script automatically. For instance, a script author of an ASP.NET page (a typical file extension is .aspx) can associate a RequiredFieldValidator control with an HTML input control of type text.
This will result in the generation of client-side script (appropriate for the Web browser), which will prevent submittal of the HTML form until the user has entered data in the HTML input box. The client-side script is generated entirely by the ASP.NET host based on attributes of the relevant controls, before the generated HTML page is sent to the browser.
Model-View-Controller (MVC) has been an important architectural pattern
in computer science for many years.
MVC was later simplified to Model-View-Controller and is a powerful and elegant means of separating concerns within an application (for example, separating data access logic from display logic)
and applies itself extremely well to web applications. Its explicit separation of concerns does add a small amount of complexity to the design of an application, but the extraordinary benefits outweigh the complexity. It has been used in dozens of frameworks since its introduction.
You will find MVC in Java and C++, on Mac and on Windows, and inside literally dozens of frameworks. The MVC separates the user interface (UI) of an application into three main aspects:
- Model: A set of classes that describes the data you are working with as well as the business rules for how the data can be changed and manipulated
- View: Defines how the UI of the application will be displayed
- Controller: A set of classes that handles communication from the user, overall application flow, and application-specific logic