| ^_^'s profilezippo,dream,real,distanc...PhotosBlogLists |
|
March 29 ASP.NET and the .NET FrameworkASP.NET is part of Microsoft's 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. ASP.NET是微软.NET框架总体战略的一部分。它包含了一组满足各种可以想象到的需求的类。在之后的两个部分,你将会学到ASP.NET是怎样融合到.NET框架中去的,而且你将会学到可以在ASP.NET页面中使用到的语言。 The .NET Framework Class Library.NET框架类库 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. 假设你就是微软,假设你必须支持多语言编程,例如VB,JS,C++。这些语言的很多函数都重复了,比如对于每种语言,你都必须包含一些访问文件系统,与数据库打交道,以及处理字符串的函数。 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? Wouldn't 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. 而.net框架类库正是如此,它包含了一组为满足变成需要而设计的类。举例来说,.net框架包含了处理数据库访问的一组类。同时还有文件系统处理类以及视图产生类。而且,他包含了更多的较为细化的用来处理正则表达式和网络协议的类。
The .NET framework, furthermore, contains classes that represent all the basic variable data types such as strings, integers, bytes, characters, and arrays. 更重要的是,.net框架还将所有一些基础变量都表示了出来,例如字符串类型,整型,字符型和数组。 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. 最重要的也是本书的主要目的,.net框架类库包含了用来建立asp.net页面的类。你需要明白的是,你可以在建立自己的asp.net页面的时候访问任何一个.net框架中的类。 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 正如你所想的,.net框架很庞大。他包含了数以千计的类。还好的是,这些类不是杂乱的拼在一起的。.net框架中的这些类是按照命名空间的各个层次组织在一起的。 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! 在asp过去的版本中,你仅仅可以访问五个标准类。想必来说,asp.net则为你提供了多达3400个类。 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. 命名空间就是对类进行逻辑上的划分。比如,所有和文件系统相关的类都被放入system.io的命名空间中。 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. 同时,命名空间也被组织为一个逻辑上的分层。在这个逻辑分层的最根部是system命名空间。这个命名空间包含了所有与基础数据类型相关的类,比如字符串和数组。同时他还包含了处理随机数和日期时间的类。 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 通过使用类的全称,你可以唯一的定位任何一个类。比如定为一个表示文件系统的file类,你可以使用以下的命名:System.IO.File System.IO refers to the namespace, and File refers to the particular class. System.IO表示命名空间,而File表示这个特殊的类。 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 Namespacesasp.net标准命名空间 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: 部分命名空间中包含的一些类是默认可以使用的,但有些命名空间则必须明确的引用进来。这些默认的命名空间包含了你最常使用的一些类。
.NET Framework-Compatible LanguagesFor purposes of this book, you will write the application logic for your ASP.NET pages using Visual Basic as your programming language. It is the default language for ASP.NET pages (and the most popular programming language in the world). Although you stick to Visual Basic in this book, you also need to understand that you can create ASP.NET pages by using any language that supports the .NET Common Language Runtime. Out of the box, this includes C# (pronounced See Sharp), JScript.NET (the .NET version of JavaScript), and the Managed Extensions to C++. NOTE The CD included with this book contains C# versions of all the code samples. Dozens of other languages created by companies other than Microsoft have been developed to work with the .NET framework. Some examples of these other languages include Python, SmallTalk, Eiffel, and COBOL. This means that you could, if you really wanted to, write ASP.NET pages using COBOL. Regardless of the language that you use to develop your ASP.NET pages, you need to understand that ASP.NET pages are compiled before they are executed. This means that ASP.NET pages can execute very quickly. The first time you request an ASP.NET page, the page is compiled into a .NET class, and the resulting class file is saved beneath a special directory on your server named Temporary ASP.NET Files. For each and every ASP.NET page, a corresponding class file appears in the Temporary ASP.NET Files directory. Whenever you request the same ASP.NET page in the future, the corresponding class file is executed. When an ASP.NET page is compiled, it is not compiled directly into machine code. Instead, it is compiled into an intermediate-level language called Microsoft Intermediate Language (MSIL). All .NET-compatible languages are compiled into this intermediate language. An ASP.NET page isn't compiled into native machine code until it is actually requested by a browser. At that point, the class file contained in the Temporary ASP.NET Files directory is compiled with the .NET framework Just in Time (JIT) compiler 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 ASP.NET page, and the .NET framework handles all the hard work of converting it into compiled code for you. ASP CLASSIC NOTE What about VBScript? Before ASP.NET, VBScript was the most popular language for developing Active Server Pages. ASP.NET 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 compiled 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, don't worry. Since VBScript is so closely related to Visual Basic, you'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 ASP.NET classes in the Temporary ASP.NET Files directory. It lists all the methods and properties of the class and enables you to view the intermediate-level code. This tool also works with all the ASP.NET controls discussed in this chapter. For example, you can use the IL Disassembler to view the intermediate-level code for the TextBox control (located in a file named System.Web.dll). March 27 Part I: Working with ASP.NET Web FormsChapter 1. Building ASP.NET Pages
In this chapter, you learn how to build basic ASP.NET Web Forms Pages. Don't let the Forms part of the name mislead you. Web Forms Pages can do much more than display standard HTML forms. Most, if not all, of the pages of your ASP.NET application will be Web Forms Pages, which enable you to create pages with interactive, dynamic, or database-driven content. 在这一章节,你将学到怎样建立一个基本的ASP.NET Web Forms Pages.不要被名字中的Forms误导了你。Web Forms Pages 可以做比仅仅显示一个普通的HTML更多的事情。在你的ASP.NET中将会多数都是Web Forms Pages,而这些将会使你创建交互的,动态的或者基于数据库内容的页面。 Web Forms Pages are pieced together out of two building blocks. First, you assemble the dynamic portion of the user interface by using ASP.NET controls. ASP.NET controls enable you to display "smart" HTML forms, for example, and present interactive grids of database data. The first part of this chapter provides an overview of all the ASP.NET controls. Web Forms Pages 被分割为两个构造的模块。首先,你将利用ASP.NET控件把用户界面的各个动态部分集合起来。ASP.NET能使你展示出精巧的HTML表格,也可以让你做出交互的数据库数据表格。此节的第一部分为你提供了关于ASP.NET空间的概况。 The second building block of a Web Forms Page is the application logic, which includes the code that executes when you click a form button, or the code that retrieves the database data displayed within a control. In the second part of this chapter, you learn how to add application logic to your Web Forms Pages to handle both control and page events. 第而部分是应用的程序的逻辑,主要包括了按钮触发事件的代码或者查询数据库数据并在控件中展示的代码。第二部分中,你将学会怎样向Web Forms Pages插入应用程序的逻辑来处理控件和页面事件。 Finally, in the last part of this chapter, you are formally introduced to the structure of an ASP.NET Web Forms Page. You learn about the different sections of a Web Forms Page and the type of content appropriate to each section. 最后,本章节的最后一部分,你将了解到一个Web Forms Pages的结构。你将了解到一个Web Forms Pages的各个部分以及各个部分之间的类似之处。 After reading this chapter, you can start creating dynamic Web sites by building interactive, dynamic pages using ASP.NET controls and handling control and page events with application logic. 完成此节的学习之后,你将能够通过使用ASP.NET控件及利用应用逻辑来处理控件和页面事件构件交互动态的页面开始创建动态的网站 Conventions Used in This BookThe following typographic conventions are used in this book:以下这些印刷体的命名规则将在本书中被使用:
March 09 Code Naming Conventions Used in This BookThe topic of variable naming and code conventions is a touchy one. Programmers tend to develop their personal naming conventions and don't like others dictating how they should write their code.变量命名规则和编码规范一直是一个比较敏感的话题。程序员更倾向于有自己的编程命名规则,他们不喜欢别人告诉他们应该怎么写自己的代码。 Nevertheless, having a common convention is valuable when code must be read by multiple people in an organization (think code reviews). Having a common convention also makes it easier to read your own code if you return to it at a later date. 不管怎样,如果会有比较多的人来阅读代码,有一个共同的编程规范更有利些(比如代码审查)。有一个共同的约定能让你在隔一段时间以后再阅读自己的代码的时候,能够很容易读懂。 The most popular variable naming convention is called Hungarian Notation. It was originally developed by Charles Simonyi at Microsoft and has been used internally at Microsoft for a number of years. According to this convention, you should name all variables starting with a standard three or four letter prefix that represents the variable's data type. For example, an integer variable used to represent a customer's age should be named intCustomerAge. 最流行的命名规范是匈牙利符号。它最初是由在微软的Charles Simonyi开发的,并且在微软内部已使用了多年。根据这个规则,你必须在命名所有变量的时候都在变量前加上三到四个字符以标示变量的数据类型。比如,一个用来表示客户年龄的变量应该命名为intCustomerAge。 Microsoft recommends that you do not follow this convention in the case of the .NET Framework and ASP.NET. The motivation for this recommendation is that they expect you to use an advanced editor, such as Microsoft Visual Studio, to write your code. Visual Studio automatically provides you with information about a variable's type. 但微软建议,如果开发.NET Framework and ASP.NET,不要使用这样的规则。这样建议的动机是他们希望在你开发的时候你可以使用一个比较高级的编辑器,比如Microsoft Visual Studio。Visual Studio能够自动为你通过一个变量的相关信息。 However, in this book, I will not assume that you are using Visual Studio to write your ASP.NET pages. In practice, developers use a wide variety of editors—such as Web Matrix, TextPad, UltraEdit, and Notepad—to write code. Since I am not assuming that you are using Visual Studio, a variable naming convention is necessary. 然而在这本书中,我将架设你并没有使用Visual Studio来编写你的ASP.NET页面。在实际中,开发人员有可能使用各种各样的编辑器,比如Web Matrix, TextPad, UltraEdit, and Notepad。正因为这样,我才觉得变量命名规则是必须的。 Furthermore, in my experience, many companies require their programmers to follow a strict naming convention that is typically some variation on the Hungarian Notation. I'll be using a variation of Hungarian Notation for the naming conventions used in this book. I've created a set of prefixes and naming conventions for the basic variable data types, ASP.NET Web Controls, ADO.NET classes, and event-handling subroutines. These conventions are listed in the following tables. 而且以我的经验来看,很多公司要求他们遵循一个比较严格的命名规范,而这些命名规范很多是匈牙利符号的一个变形。在本书中我也会使用这样一种命名规则。我已经为一些基本变量类型,ASP.NET web控件, ADO.NET 类和 事件处理子程序建立了一组前缀及命名规则。 My goal is not to provide a standard prefix for each and every class in the .NET Framework. That would require over 3,400 standard prefixes! The goal is to provide standard prefixes for the most common types that you would use in ASP.NET.
Event-Handling SubroutinesThe name of an event-handling subroutine will consist of the ID of the control that raised the event followed by the type of event being handled. For example, a subroutine named btnSubmit_Click handles the Click event of a Button control named btnSubmit. 事件处理子程序的名字由触发此事件的控件ID和被处理事件的类型组成。举例来说,一个叫做btnSubmit_Click的事件则是处理一个名叫btnSubmit的按钮的单击事件的。 When a control that raises an event is not assigned an ID, the type of the control is used instead of the ID. For example, the subroutine named Button_Click handles the Click event of a Button control without an ID. 当一个没有任何ID的控件触发一个事件时,控件类型将取代ID在命名中出现。Button_Click则是处理一个无ID的按钮的单击事件。 March 08 How This Book Is OrganizedAlthough I encourage you to read this book from start to finish, reading chapter by chapter, I realize that not everyone has time to do so. If necessary, you can use this book solely as a reference and jump to a chapter only when the need arises. It might be helpful, therefore, to have an idea of the overall organization of this book.尽管我建议你把这本书从头到尾都读完,但我意识到不是谁都有足够的时间。如果必要的话,你可以仅仅把它当作一本参考资料来看,仅在需要的时候跳到相应的章节。所以了解到这个文章的结构对你还是有些帮助的。
March 03 IntroductionAbout the AuthorAbout the AuthorStephen Walther a well-known ASP.NET expert and trainer, has provided training to companies and organizations throughout the United States including NASA, Verizon, MetLife, and the National Science Foundation through his company Superexpert AspWorkshops (www.AspWorkshops.com). He was the lead developer of the ASP.NET Community Starter Kit, a "best-practices" application released by Microsoft. Stephen was the past Chief Technical Officer of CityAuction (www.cityauction.com), one of the Internet's top person-to-person auction Web sites, and the exclusive auction provider for both Snap! and CitySearch. Stephen was also past Chief Technical Officer of Collegescape, the leading provider of online college applications.
关于作者 Stephen Walther 在ASP。NET方面是一个知名的专家和培训者。通过他的公司,他向全美国各个地方的公司和机构提供培训课程。他曾经是微软发布的一款软件---ASP.NET Community Starter Kit的首席开发工程师。他还是一家从事私人交易的网站的技术总监,同时,他也曾经是Collegescape,一家提供网上大学教程的公司的技术总监。 |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|