【正文】
ultiple programming languages— such as Visual Basic, JScript, and C++. A great deal of the functionality of these programming languages overlaps. For example, for each language, you would have to include methods for accessing the file system, working with databases, and manipulating strings. Furthermore, these languages contain similar programming constructs. Every language, for example, can represent loops and conditionals. Even though the syntax of a conditional written in Visual Basic differs from the syntax of a conditional written in C++, the programming function is the same. Finally, most programming languages have similar variable data types. In most languages, you have some means of representing strings and integers, for example. The maximum and minimum size of an integer might depend on the language, but the basic data type is the same. Maintaining all this functionality for multiple languages requires a lot of work. Why keep reinventing the wheel? Wouldn39。t piled into native machine code until it is actually requested by a browser. At that point, the class file contained in the Temporary Files directory is piled with the .NET framework Just in Time (JIT) piler and executed. The magical aspect of this whole process is that it happens automatically in the background. All you have to do is create a text file with the source code for your page, and the .NET framework handles all the hard work of converting it into piled code for you. ASP CLASSIC NOTE What about VBScript? Before , VBScript was the most popular language for developing Active Server Pages. does not support VBScript, and this is good news. Visual Basic is a superset of VBScript, which means that Visual Basic has all the functionality of VBScript and more. So, you have a richer set of functions and statements with Visual Basic. Furthermore, unlike VBScript, Visual Basic is a piled language. This means that if you use Visual Basic to rewrite the same code that you wrote with VBScript, you can get better performance. If you have worked only with VBScript and not Visual Basic in the past, don39。ll find it easy to make the transition between the two languages. NOTE Microsoft includes an interesting tool named the IL Disassembler (ILDASM) with the .NET framework. You can use this tool to view the disassembled code for any of the classes in the Temporary Files directory. It lists all the methods and properties of the class and enables you to view the intermediatelevel code. This tool also works with all the controls discussed in this chapter. For example, you can use the IL Disassembler to view the intermediatelevel code for the TextBox control (located in a file named ). Introducing Controls controls provide the dynamic and interactive portions of the user interface for your Web application. The controls render the content that the users of your Web site actually see and interact with. For example, you can use controls to create HTML form elements, interactive calendars, and rotating banner advertisements. controls coexist peacefully with HTML content. Typically, you create the static areas of your Web pages with normal HTML content and create the dynamic or interactive portions with controls. The best way to understand how controls work in an HTML page is to look at a simple Web Forms Page. Adding Application Logic to an Page The second building block of an page is the application logic, which is the actual programming code in the page. You add application logic to a page to handle both control and page events. If a user clicks a Button control within an HTML form, for example, the Button control raises an event (the Click event). Typically, you want to add code to the page that does something in response to this event. For example, when someone clicks the Button control, you might want to save the form data to a file or database. Controls are not the only things that can raise events. An page itself raises several events every time it is requested. For example, whenever you request a page, the page39。 they are the formatting properties of the base control class. Next, you learn how to apply Cascading Style Sheet styles and classes to Web controls. 3. Performing Form Validation with Validation Controls Using Clientside Validation Traditionally, Web developers have faced a tough choice when adding form validation logic to their pages. You can add form validation routines to your serverside code, or you can add the validation routines to your clientside code. The advantage of writing validation logic in clientside code is that you can provide instant feedback to your users. For example, if a user neglects to enter a value in a required form field, you can instantly display an error message without requiring a roundtrip back to the server. People really like clientside validation. It looks great and creates a better overall user experience. The problem, however, is that it does not work with all browsers. Not all browsers support JavaScript, and different versions of browsers support different versions of JavaScript, so clientside validation is never guaranteed to work. For this reason, in the past, many developers decided to add all their form validation logic exclusively to serverside code. Because serverside code functions correctly with any browser, this course of action was safer. Fortunately, the Validation controls discussed in this chapter do not force you to make this difficult choice. The Validation controls automatically generate both clientside and serverside code. If a browser is capable of supporting JavaScript, clientside validation scripts are automatically sent to the browser. If a browser is incapable of supporting JavaScript, the validation routines are automatically implemented in serverside code. You should be warned, however, that clientsi