.NET技术外文翻译资料

 2022-11-21 04:11

.NET Technique

1. Building .NET Pages

.NET and the .NET Framework

.NET is part of Microsofts overall .NET framework, which contains a vast set of programming classes designed to satisfy any conceivable programming need. In the following two sections, you learn how .NET fits within the .NET framework, and you learn about the languages you can use in your .NET pages.

The .NET Framework Class Library

Imagine that you are Microsoft. Imagine that you have to support multiple 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? Wouldnt it be easier to create all this functionality once and use it for every language?

The .NET Framework Class Library does exactly that. It consists of a vast set of classes designed to satisfy any conceivable programming need. For example, the .NET framework contains classes for handling database access, working with the file system, manipulating text, and generating graphics. In addition, it contains more specialized classes for performing tasks such as working with regular expressions and handling network protocols.

The .NET framework, furthermore, contains classes that represent all the basic variable data types such as strings, integers, bytes, characters, and arrays. Most importantly, for purposes of this book, the .NET Framework Class Library contains classes for building .NET pages. You need to understand, however, that you can access any of the .NET framework classes when you are building your .NET pages.

Understanding Namespaces

As you might guess, the .NET framework is huge. It contains thousands of classes (over 3,400). Fortunately, the classes are not simply jumbled together. The classes of the .NET framework are organized into a hierarchy of namespaces.

.NET Classic Note

In previous versions of Active Server Pages, you had access to only five standard classes (the Response, Request, Session, Application, and Server objects). .NET, in contrast, provides you with access to over 3,400 classes!

A namespace is a logical grouping of classes. For example, all the classes that relate to working with the file system are gathered together into the System.IO namespace.

The namespaces are organizedin to a hierarchy (a logical tree). At the root of the tree is the System namespace. This namespace contains all the classes for the base data types, such as strings and arrays. It also contains classes for working with random numbers and dates and times.

You can uniquely identify any class in the .NET framework by using the full namespace of the class. For example, to uniquely refer to the class that represents a file system file (the File class), you would use the following:

System.IO.File

System.IO refers to the namespace, and File refers to the particular class.

NOTE

You can view all the namespaces of the standard classes in the .NET Framework Class Library by viewing the Reference Documentation for the .NET Framework.

Standard .NET Namespaces

The classes contained in a select number of namespaces are available in your .NET pages by default. (You must explicitly import other namespaces.) These default namespaces contain classes that you use most often in your .NET applications:

System— Contains all the base data types and other useful classes such as those related to generating random numbers and working with dates and times.

System.Collections— Contains classes for working with standard collection types such as hash tables, and array lists.

System.Collections.Specialized— Contains classes that represent specialized collections such as linked lists and string collections.

System.Configuration— Contains classes for working with configuration files (Web.config files).

System.Text— Contains classes for encoding, decoding, and manipulating the contents of strings.

System.Text.RegularExpressions— Contains classes for performing regular expression match and replace operations.

System.Web— Contains the basic classes for working with the World Wide Web, including classes for representing browser requests and server responses.

System.Web.Caching— Contains classes used for caching the content of pages and classes for performing custom caching operations.

System.Web.Security— Contains classes for implementing authentication and authorization such as Forms and Passport authentication.

System.Web.SessionState — Contains classes for implementing session state.

System.Web.UI— Contains the basic classes used in building the user interface of .NET pages.

System.Web.UI.HTMLControls — Contains the classes for the HTML controls.

System.Web.UI.WebControls— Contains the classes for the Web controls.

.NET Framework-Compatible Languages

For purposes of this book, you will write the application logic fo

剩余内容已隐藏,支付完成后下载完整资料


.NET技术

1.建立.NET页面

.NET和.NET框架

.NET是微软整体.NET框架的一部分,它包含了大量的编程类,旨在满足任何可以想象的编程需求。在以下两节中,您将了解.NET如何适应.NET框架,以及可以在.NET页面中使用的语言。

.NET框架类库

想象一下,你是微软公司的一分子,你的产品必须支持多种编程语言,比如Visual Basic,JScript和C 。这些编程语言的很多功能都有重叠。例如,对于每种语言,您都必须包含访问文件系统,使用数据库和操纵字符串的方法。

而且,这些语言包含类似的编程结构。例如,每种语言都可以表示循环和条件。即使用Visual Basic编写的条件语法与用C 编写的条件语法不同,编程功能也是一样的。

最后,大多数编程语言都有类似的可变数据类型。例如,在大多数语言中,都有一些表示字符串和整数的方法。整数的最大和最小大小可能取决于语言,但基本数据类型相同。

为多种语言维护所有这些功能需要很多工作。为什么我们要不断研发它们呢?创建所有这些功能并将其用于每种语言会不会更容易?

.NET Framework类库正是如此。它由大量的类组成,旨在满足任何可能的编程需求。例如,.NET框架包含用于处理数据库访问,处理文件系统,处理文本和生成图形的类。另外,它还包含更多专门的类,用于执行诸如处理正则表达式和处理网络协议等任务。

此外,.NET框架包含表示所有基本变量数据类型的类,如字符串,整数,字节,字符和数组。最重要的是,就本书而言,.NET Framework类库包含用于构建.NET页面的类。但是,您需要了解在构建.NET页面时可以访问任何.NET框架类。

了解命名空间

正如你可能猜到的,.NET框架是巨大的。它包含数千个类(超过3,400个)。幸运的是,这些累不是简单地混杂在一起。 .NET框架的类被组织到命名空间的层次结构中。

.NET经典注释

在之前的Active Server Pages版本中,只能访问五个标准类(响应,请求,会话,应用程序和服务器对象)。相反,.NET为您提供了超过3,400个类的访问权!

名称空间是类的逻辑分组。例如,与文件系统一起工作的所有类都被汇集到System.IO名称空间中。

命名空间被组织成一个层次结构(一个逻辑树)。在树的根部是System命名空间。该名称空间包含基础数据类型的所有类,例如字符串和数组。它还包含用于处理随机数字和日期和时间的类。

您可以使用类的完整名称空间来唯一标识.NET框架中的任何类。例如,要唯一地引用表示文件系统文件(File类)的类,可以使用以下内容:

System.IO.File

System.IO引用命名空间,File引用特定的类。

注意

通过查看.NET Framework的参考文档,您可以在.NET Framework类库中查看标准类的所有命名空间。

标准的.NET命名空间

默认情况下,.NET页面中包含选定数量的命名空间中包含的类。 (您必须显式导入其他名称空间。)这些默认名称空间包含您在.NET应用程序中最常使用的类:

系统 - 包含所有基本数据类型和其他有用的类,例如与生成随机数和处理日期和时间有关的类。

System.Collections-包含用于处理标准集合类型(如散列表和数组列表)的类。

System.Collections.Specialized - 包含表示专用集合(如链接列表和字符串集合)的类。

System.Configuration-包含用于处理配置文件(Web.config文件)的类。

System.Text-包含用于编码,解码和操纵字符串内容的类。

System.Text.RegularExpressions-包含用于执行正则表达式匹配和替换操作的类。

System.Web-包含用于使用万维网的基本类,包括用于表示浏览器请求和服务器响应的类。

System.Web.Caching-包含用于缓存执行定制缓存操作的页面和类的内容的类。

System.Web.Security-包含用于实现身份验证和授权的类,例如Forms和Passport身份验证。

System.Web.SessionState - 包含用于实现会话状态的类。

System.Web.UI-包含用于构建.NET页面的用户界面的基本类。

System.Web.UI.HTMLControls - 包含HTML控件的类。

System.Web.UI.WebControls-包含Web控件的类。

.NET Framework兼容的语言

为了达到本书的目的,您将使用Visual Basic作为您的编程语言编写.NET页面的应用程序逻辑。它是.NET页面的默认语言。虽然您在本书中使用Visual Basic,但您还需要了解可以使用任何支持.NET Common Language Runtime的语言来创建.NET页面。开箱即用,包括C#,JScript.NET和扩展的C 。

注意

本书附带的CD包含所有代码示例的C#版本。由微软以外的公司创建的其他几十种语言已经被开发出来用于.NET框架。这些其他语言的一些例子包括Python,SmallTalk,Eiffel和COBOL。这意味着你可以使用COBOL编写.NET页面。

无论您用于开发.NET页面的语言如何,您都需要了解.NET页面在执行前已编译好。这意味着.NET页面可以很快执行。

当您第一次请求.NET页面时,该页面将被编译为.NET类,并将生成的类文件保存在服务器上名为Temporary .NET Files的特殊目录下。对于每个.NET页面,相应的类文件都出现在Temporary .NET Files目录中。每当您将来请求相同的.NET页面时,都会执行相应的类文件。

.NET页面编译时,不会直接编译到机器代码中。相反,它被编译成一种名为Microsoft Intermediate Language(MSIL)的中级语言。所有与.NET兼容的语言都被编译为这种中间语言。

.NET页面在被浏览器实际请求之前不会被编译为本地机器代码。此时,Temporary .NET Files目录中包含的类文件将使用.NET框架即时(JIT)编译器进行编译并执行。

整个过程的神奇之处是它在后台自动发生。你所要做的就是创建一个带有.NET页面源代码的文本文件,.NET框架可以处理将它转换为编译代码所需的所有复杂工序。

.NET经典笔记

什么关于VBScript?在.NET之前,VBScript是开发Active Server Pages的最流行的语言。

.NET不支持VBScript,这是个好消息。 Visual Basic是VBScript的超集,这意味着Visual Basic具有VBScript等所有功能。因此,您可以通过Visual Basic获得更丰富的函数和语句。

此外,与VBScript不同,Visual Basic是一种编译语言。这意味着如果您使用Visual Basic重写您使用VBScript编写的相同代码,则可以获得更好的性能。

如果您以前只使用VBScript而不使用Visual Basic,请不要担心。由于VBScript与Visual Basic紧密相关,因此您可以轻松地在两种语言之间进行切换。

注意

Microsoft在.NET框架中包含一个名为IL Disassembler(ILDASM)的有趣工具。您可以使用此工具查看Temporary .NET Files目录中任何.NET类的反汇编代码。它列出了该类的所有方法和属性,并允许您查看中级代码。

该工具也适用于本章讨论的所有.NET控件。例如,可以使用IL反汇编程序查看TextBox控件的中间级代码(位于名为System.Web.dll的文件中)。

介绍.NET控件

.NET控件为您的Web应用程序提供用户界面的动态和交互式部分。控件呈现网站用户实际看到并与之交互的内容。例如,您可以使用控件创建HTML表单元素,交互式日历和旋转横幅广告。

.NET控件与HTML内容和平共存。通常,您可以使用普通的HTML内容创建网页的静态区域,并创建动态或交互式

与.NET控件的部分。

了解.NET控件如何在HTML页面中工作的最佳方式是查看简单的Web窗体页面。

将应用程序逻辑添加到.NET页面

.NET页面的第二个构建块是应用程序逻辑,它是页面中的实际编程代码。您可以将应用程序逻辑添加到页面以处理控件和页面事件。

例如,如果用户单击HTML表单中的Button控件,Button控件将引发一个事件(Click事件)。通常情况下,您希望将代码添加到对此事件做出响应的页面中。例如,当有人单击Button控件时,可能需要将表单数据保存到文件或数据库。

控制不是唯一可以引发事件的事情。每次请求时,.NET页面本身都会引发多个事件。例如,无论您何时请求一个页面,该页面的Load事件都会被触发。您可以将应用程序逻辑添加到每当Load事件发生时执行的页面。

2.使用Web服务器控件构建表单

构建智能表单

您使用几个基本的Web控件来表示标准HTML表单元素,如单选按钮,文本框和列表框。您可以在.NET页面中使用这些控件来为您的Web应用程序创建用户界面。以下各节提供了每个这些Web控件的详细概述和编程示例。

控制页面导航

在下面的章节中,您将学习如何控制用户如何从一个.NET页面移动到另一个页面。首先,您将学习如何将HTML表单提交到其他页面并检索表单信息。接下来,您将学习如何使用Redirect()方法自动将用户转移到新页面。最后,您将学习如何将页面与HyperLink控件链接在一起。

将格式应用于控件

在下面的章节中,您将学习如何制作更具吸引力的Web表单。首先,您将看到所有Web控件通用的格式属性概述;它们是基本控件类的格式属性。接下来,您将学习如何将层叠样式表样式和类应用于Web控件。

3.使用验证控件执行表单验证

使用客户端验证

传统上,Web开发人员在向他们的页面添加表单验证逻辑时面临艰难的选择。您可以将表单验证例程添加到服务器端代码,也可以将验证例程添加到客户端代码中。

在客户端代码中编写验证逻辑的优点是您可以向用户提供即时反馈。例如,如果用户忽略在所需表单域中输入值,则可以立即显示错误消息,而无需往返回服务器。人们非常喜欢客户端验证。它看起来很棒,创造出更好的整体用户体验。

但问题是,它不适用于所有浏览器。并非所有浏览器都支持JavaScript,而且不同版本的浏览器支持不同版本的JavaScript,因此客户端验证无法保证正常工作。

出于这个原因,过去,许多开发人员决定将所有的表单验证逻辑专门添加到服务器端代码中。由于服务器端代码在任何浏览器中都能正常运行,因此这一行动更安全。

幸运的是,本章中讨论的验证控件,并不强迫您做出这个困难的选择。验证控件自动生成客户端和服务器端代码。如果浏览器能够支持JavaScript,则客户端验证脚本会自动发送到浏览器。如果浏览器不支持JavaScript,则验证例程将自动在服务器端代码中实现。

但是,客户端验证法仅适用于Microsoft Internet Explorer 4.0及更高版本。特别是,本章讨论的客户端脚本不适用于任何版本的Netscape Navigator。

请求字段:RequiredFieldValidator控件

您在Web窗体中使用RequiredFieldValidator来检查控件是否有值。通常,您使用此控件与TextBox控件。但是,将RequiredFieldValidator与其他输入控件(如RadioButtonList)一起使用并没有什么问题。

验证表达式:RegularExpressionValidator控件

您可以使用RegularExpressionValidator将输入到表单字段的值与正则表达式匹配。您可以使用此控件来检查用户是否输入了例如有效的电子邮件地址,电话号码或用户名或密码。以下部分提供了如何使用正则表达式执行所有这些验证任务的示例。

比较值:CompareValidator控件

CompareValidator控件执行输入到表单域的数据和另一个值之间的比较。另一个值可以是一个固定值,例如特定数字,或输入另一个控件的值。

总结性错误:Valid

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[22953],资料为PDF文档或Word文档,PDF文档可免费转换为Word

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。