ASP.NET Technique
1. Building ASP.NET Pages
ASP.NET and the .NET Framework
ASP.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 ASP.NET fits within the .NET framework, and you learn about the languages you can use in your ASP.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 ASP.NET pages. You need to understand, however, that you can access any of the .NET framework classes when you are building your ASP.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.
ASP 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). ASP.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 organized into 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 ASP.NET Namespaces
The classes contained in a select number of namespaces are available in your ASP.NET pages by default. (You must explicitly import other namespaces.) These default namespaces contain classes that you use most often in your ASP.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. 剩余内容已隐藏,支付完成后下载完整资料
Advanced ASP.NET AJAX Server Controls ,2009, 177(5): 97-102.
要保留各种不同语言的这种功能一致性需要非常大的工作量。我们为什么一定要重头再来呢?如果把这些语言中的相同功能,全部重写一遍,并兼容每一种语言,这么做岂不是更省力?
除此以外,.NET框架中还内置了所有基本数据类型的包装类,这些数据类型有:字符串、整数类型、字符还有数组等。
这本书的意图,最关键的是,.NET框架中容纳了用来构建ASP.NET页面的类。然而,你需要明白的是,当你构建ASP页面时你可以访问几乎所有的.NET框架的类。
正如你所料想的,.NET框架是非常庞大的,它包含成千上万的类(有3400多个)。更有意思的是,这些类并不是简单地堆砌在一起。.NET框架中的类被整合到一个有层次的命名空间里。
在早期ASP版本中,用户只能访问五个标准类:请求类、响应类、会话类、应用类和服务器对象。相比而言,ASP.NET可以访问的类,超过3400个!
一个命名空间,是类的逻辑组合。比如说,与文件系统工作相关联的类,都聚集在IO系统中。这个命名空间,包含所有基本数据类型包装类,如字符串和数组。它还包括,提供随机数和日期时间的类。
你可以在.NET框架类库中,浏览所有标准类的命名空间,通过阅读.NET框架的参考文档。
默认条件下,在系统默认导入的命名空间中的一部分类,可以直接用在你的ASP.NET页面中(别的命名空间的类要使用必须显示导入)。默认命名空间中,有以下这些在ASP.NET应用中最常用到的类:
System--封装了所有基本数据类型和一些有用的类,比如与随机数和时间日期相关的类。
System.Collections--里面有所有标准集合类,如哈希表和array lists。
System.Collections.Specialized--包含那些特殊的集合类,比如链表和字符串集合。
System.Configuration--里面主要是操作配置文件的类(Web.config files)。
System.Text--封装了编码、解码和操作字符目录的类。
System.Text.RegularExpressions--主要是可以用来对正则表达式进行匹配,和替换操作的类。
System.Web--里面是工作在www万维网的类,这些类能够处理浏览器请求和服务器响应等。
System.Web.Caching--里面封装了处理页面缓存,还有自定义缓冲区操作的类。
System.Web.Security--主要封装进行身份验证、授权的类,比如表单和身份验证。
System.Web.SessionState--里面有实现会话状态的类。
System.Web.UI--封装了用来构建ASP.NET用户接口页面的基础类。
System.Web.UI.HTMLControls--包括了用于HTML控件的类。
System.Web.UI.WebControls--封装了用于页面控件的类。
无论使用什么语言来搭建ASP.NET页面,你需要明白的是,ASP.NET在执行前必须要编译。这意味着,ASP.NET能够以很快的速度执行。
当一个ASP.NET页面被编译时,它没有直接编译成机器码,而是被编译成一个中间语言,叫MSIL。.NET中所有被兼容的语言,都能被编译成中间语言MSIL。
这整个过程中,比较神奇的地方在于,它是在后台自动进行的。你所要做的是,用你的ASP.NET源代码,创建一个文本文件,而转换成目标代码的工作,完全是由.NET框架来完成的。
那么,VBScript是什么呢?在ASP.NET之前,VBScript是用来开发动态服务页面,最流行的语言。
此外,和VBScript不同,Visual Basic是一种编译语言。这意味着,如果你用Visual Basic来重写,已经写过的相同的VBScript代码,你将会获得更好的用户体验。
如果你以前仅仅用过VBScript,没有接触过Visual Basic,不用担心,因为VBScript和Visual Basic非常相似,你会发现,在这两种语言之间转换并不难。
在本章中讨论的这个工具,也可以用于所有的ASP.NET控件。比如说,你可以使用IL Disassembler,去浏览TextBox控件(在一个叫System.Web.dll的文件中)的中间代码。
ASP.NET为你的web应用程序,提供了动态可交互的用户接口。这些控件呈现的内容,可以被你网站的用户看见并交互。比如说,你可以使用控件,创建HTML表单元素、编写交互式日历或者滚动标题广告。
ASP.NET控件和HTML,可以很好的兼容。通常,你会使用标准的HTML来编写web页面的静态部分,使用ASP.NET控件来实现动态交互的部分。
要理解ASP.NET控件是如何正常工作在HTML页面的,最好的办法是,观察一个简单的web表单页面。
ASP.NET页面的第二个组件,就是应用程序逻辑,这是页面中实际的编程代码。为页面添加应用程序逻辑,既能处理控件,也能处理页面事件。
在下面步骤中,你会学习如何制作更有吸引力的web表单。首先,你需要查看所有web控件的常用格式属性;这些是基础控件类的格式属性。然后,你会学习如何在web控件中,应用样式表风格和格式类。
习惯上,web开发者在为页面添加表单验证逻辑时,会面临一个困难的选择。你可以在服务端代码中添加表单验证规则,或者你也可以添加表单验证规则到你的客户端代码中。
在客户端添加验证逻辑的好处是,你可以立即向你的用户提供反馈信息。就比如,如果用户没有给一个表单字段键入一个值,那么,你可以立即显示错误信息,而不需要返回服务器进行验证。
然而你需要警惕的是,客户端验证仅仅支持微软IE v4.0及以上的版本。尤其需要注意,在本章讨论的客户端脚本不支持任何版本的Netscape Navigator浏览器。
请求字段:The RequiredFieldValidator控件
在web表单中,你会使用RequiredFieldValidator来检测一个值是否为空。通常情况下,你会和TextBox控件,一起使用这个控件。然而,如果你和其他输入控件一起使用RequiredF-
资料编号:[146494],资料为PDF文档或Word文档,PDF文档可免费转换为Word
以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。