【正文】
中這些默認的命名空間使你在 。 包含頁面緩沖內(nèi)容和自定義 緩沖操作的類。第一次請求 ,頁面被編譯成一個 .NET類 ,這個類文件被保存在一個特殊的目錄下,這個目錄的名字叫Temporary Files。你可以添加窗體頁面驗證規(guī)則到你的服務器端代碼,也可以添加驗證規(guī)則到你的客戶端代碼。因為服務器端代碼能夠和任何瀏覽器協(xié)同工作。例如:你能使用這控件來檢查一個用戶是否輸入一個合法的電子郵件地址,電話號碼,用戶名或密碼 。舉例來說,如果你輸入文本到一個 Lebel標簽上然后提交那個頁面,當那個頁面再次被訪問時那個 Lebel標簽的內(nèi)容將會被保存下來。 使用 Visible and Enabled屬性 每個控件 ,包括 HTML和 Web控件 ,有一個 Visible 屬性來決定那個控件是否可 見。 在準備進行部署時,有多種可選方案。 C 的大括號語法使任何熟悉 C、 C++ 或 Java 的人都可以立即上手。重寫父類中的虛方法的各種方法要求 override 關(guān)鍵字作為一種避免意外重定義的方式。在直接內(nèi)存訪問必不可少的情況下, C 甚至支持指針和 “不安全 ”代碼的概念。 IL 代碼與資源(如位圖和字符串)一起作為一種稱為程序集的可執(zhí)行文件存儲在磁盤上,通常具有的擴展名為 .exe 或 .dll。因為由 C 編譯器生成的 IL 代碼符合公共類型規(guī)范 (CTS),因此從 C 生成的 IL 代碼可以與從 Visual Basic、Visual C++、 Visual J 的 .NET 版本或者其他 20 多種符合 CTS 的語言中的任何一種生成的代碼進行交互。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. Forms with Web Server Controls Useingseveral of the basic Web controls to represent standard HTML form elements such as radio buttons, text boxes, and list boxes. You can use these controls in your pages to create the user interface for your Web application.. Form Validation with Validation Controls 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 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 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. At the same time, 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. Requiring Fields: The RequiredFieldValidator Control You use RequiredFieldValidator in a Web form to check whether a control has a value. Typically, you use this control with a TextBox control. However, nothing is wrong with using RequiredFieldValidator with other input controls such as RadioButtonList. Validating Expressions: The RegularExpressionValidator Control You can use RegularExpressionValidator to match the value entered into a form field to a regular expression. You can use this control to check whether a user has entered, for example, a valid address, telephone number, or username or password. Samples of how to use a regular expression to perform all these validation tasks are provided in the following sections. Comparing Values: The CompareValidator Control The CompareValidator control performs parisons between the data entered into a form field and another value. The other value can be a fixed value, such as a particular number, or a value entered into another control. Summarizing Errors: The ValidationSummary Control Imagine that you have a form with 50 form fields. If you use only the Validation controls discussed in the previous sections of this chapter to display errors, seeing an error message on the page might be difficult. For example, you might have to scroll down to the 48th form field to find the error message. Fortunately, Microsoft includes a ValidationSummary control with the Validation controls. You can use this control to summarize all the errors at the top of a page, or wherever else you want. Control Programming Working with View State By default, almost all controls retain the values of their properties between form posts. For example, if you assign text to a Label control and submit the form, when the page is rendered again, the contents of the Label control are preserved. The magic of view state is that it does not depend on any special server or browser properties. In particular, it does not depend on cookies, session variables, or applicatio