計算機專業(yè)畢業(yè)外文翻譯--asp.net 技術(shù)_第1頁
已閱讀1頁,還剩15頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、<p>  ASP.NET Technique </p><p>  1. Building ASP.NET Pages</p><p>  ASP.NET and the .NET Framework</p><p>  ASP.NET is part of Microsoft's overall .NET framework, which c

2、ontains 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 c

3、an use in your ASP.NET pages.</p><p>  The .NET Framework Class Library</p><p>  Imagine that you are Microsoft. Imagine that you have to support multiple programming languages—such as Visual Ba

4、sic, 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, a

5、nd manipulating strings.</p><p>  Furthermore, these languages contain similar programming constructs. Every language, for example, can represent loops and conditionals. Even though the syntax of a condition

6、al written in Visual Basic differs from the syntax of a conditional written in C++, the programming function is the same.</p><p>  Finally, most programming languages have similar variable data types. In mos

7、t 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.</p><p>  Main

8、taining 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?</p><

9、p>  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

10、 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 prot

11、ocols.</p><p>  The .NET framework, furthermore, contains classes that represent all the basic variable data types such as strings, integers, bytes, characters, and arrays.</p><p>  Most importa

12、ntly, 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

13、your ASP.NET pages.</p><p>  Understanding Namespaces</p><p>  As you might guess, the .NET framework is huge. It contains thousands of classes (over 3,400). Fortunately, the classes are not sim

14、ply jumbled together. The classes of the .NET framework are organized into a hierarchy of namespaces.</p><p>  ASP Classic Note</p><p>  In previous versions of Active Server Pages, you had acce

15、ss 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!</p><p>  A namespace is a logical gro

16、uping of classes. For example, all the classes that relate to working with the file system are gathered together into the System.IO namespace.</p><p>  The namespaces are organized into a hierarchy (a logica

17、l 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 an

18、d times.</p><p>  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

19、class), you would use the following:</p><p>  System.IO.File</p><p>  System.IO refers to the namespace, and File refers to the particular class.</p><p><b>  NOTE</b><

20、;/p><p>  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.</p><p>  Standard ASP.NET Namesp

21、aces</p><p>  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 th

22、at you use most often in your ASP.NET applications:</p><p>  System— Contains all the base data types and other useful classes such as those related to generating random numbers and working with dates and ti

23、mes.</p><p>  System.Collections— Contains classes for working with standard collection types such as hash tables, and array lists.</p><p>  System.Collections.Specialized— Contains classes that

24、 represent specialized collections such as linked lists and string collections.</p><p>  System.Configuration— Contains classes for working with configuration files (Web.config files).</p><p>  

25、System.Text— Contains classes for encoding, decoding, and manipulating the contents of strings.</p><p>  System.Text.RegularExpressions— Contains classes for performing regular expression match and replace o

26、perations.</p><p>  System.Web— Contains the basic classes for working with the World Wide Web, including classes for representing browser requests and server responses.</p><p>  System.Web.Cach

27、ing— Contains classes used for caching the content of pages and classes for performing custom caching operations.</p><p>  System.Web.Security— Contains classes for implementing authentication and authorizat

28、ion such as Forms and Passport authentication.</p><p>  System.Web.SessionState— Contains classes for implementing session state.</p><p>  System.Web.UI— Contains the basic classes used in build

29、ing the user interface of ASP.NET pages.</p><p>  System.Web.UI.HTMLControls— Contains the classes for the HTML controls.</p><p>  System.Web.UI.WebControls— Contains the classes for the Web con

30、trols.</p><p>  .NET Framework-Compatible Languages</p><p>  For purposes of this book, you will write the application logic for your ASP.NET pages using Visual Basic as your programming languag

31、e. It is the default language for ASP.NET pages. 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

32、 Runtime. Out of the box, this includes C#, JScript.NET, and the Managed Extensions to C++.</p><p><b>  NOTE</b></p><p>  The CD included with this book contains C# versions of all t

33、he code samples.</p><p>  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, Small

34、Talk, Eiffel, and COBOL. This means that you could, if you really wanted to, write ASP.NET pages using COBOL.</p><p>  Regardless of the language that you use to develop your ASP.NET pages, you need to under

35、stand that ASP.NET pages are compiled before they are executed. This means that ASP.NET pages can execute very quickly.</p><p>  The first time you request an ASP.NET page, the page is compiled into a .NET c

36、lass, 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 dir

37、ectory. Whenever you request the same ASP.NET page in the future, the corresponding class file is executed.</p><p>  When an ASP.NET page is compiled, it is not compiled directly into machine code. Instead,

38、it is compiled into an intermediate-level language called Microsoft Intermediate Language (MSIL). All .NET-compatible languages are compiled into this intermediate language.</p><p>  An ASP.NET page isn'

39、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) com

40、piler and executed.</p><p>  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,

41、and the .NET framework handles all the hard work of converting it into compiled code for you.</p><p>  ASP CLASSIC NOTE</p><p>  What about VBScript? Before ASP.NET, VBScript was the most popula

42、r language for developing Active Server Pages.</p><p>  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 functionali

43、ty of VBScript and more. So, you have a richer set of functions and statements with Visual Basic.</p><p>  Furthermore, unlike VBScript, Visual Basic is a compiled language. This means that if you use Visual

44、 Basic to rewrite the same code that you wrote with VBScript, you can get better performance.</p><p>  If you have worked only with VBScript and not Visual Basic in the past, don't worry. Since VBScript

45、is so closely related to Visual Basic, you'll find it easy to make the transition between the two languages.</p><p><b>  NOTE</b></p><p>  Microsoft includes an interesting tool

46、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 proper

47、ties of the class and enables you to view the intermediate-level code.</p><p>  This tool also works with all the ASP.NET controls discussed in this chapter. For example, you can use the IL Disassembler to v

48、iew the intermediate-level code for the TextBox control (located in a file named System.Web.dll).</p><p>  Introducing ASP.NET Controls</p><p>  ASP.NET controls provide the dynamic and interact

49、ive 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,

50、 interactive calendars, and rotating banner advertisements.</p><p>  ASP.NET controls coexist peacefully with HTML content. Typically, you create the static areas of your Web pages with normal HTML content a

51、nd create the dynamic or interactive portions with ASP.NET controls.</p><p>  The best way to understand how ASP.NET controls work in an HTML page is to look at a simple Web Forms Page.</p><p> 

52、 Adding Application Logic to an ASP.NET Page</p><p>  The second building block of an ASP.NET page is the application logic, which is the actual programming code in the page. You add application logic to a p

53、age to handle both control and page events.</p><p>  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

54、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.</p><p>  Controls are not the only

55、things that can raise events. An ASP.NET page itself raises several events every time it is requested. For example, whenever you request a page, the page's Load event is triggered. You can add application logic to th

56、e page that executes whenever the Load event occurs.</p><p>  2. Building Forms with Web Server Controls</p><p>  Building Smart Forms</p><p>  You use several of the basic Web cont

57、rols to represent standard HTML form elements such as radio buttons, text boxes, and list boxes. You can use these controls in your ASP.NET pages to create the user interface for your Web application. The following secti

58、ons provide detailed overviews and programming samples for each of these Web controls.</p><p>  Controlling Page Navigation</p><p>  In the following sections, you learn how to control how a use

59、r moves from one ASP.NET page to another. First, you learn how to submit an HTML form to another page and retrieve form information. Next, you learn how to use the Redirect() method to automatically transfer a user to a

60、new page. Finally, you learn how to link pages together with the HyperLink control.</p><p>  Applying Formatting to Controls</p><p>  In the following sections, you learn how to make more attrac

61、tive Web forms. First, you look at an overview of the formatting properties common to all Web controls; they are the formatting properties of the base control class. Next, you learn how to apply Cascading Style Sheet sty

62、les and classes to Web controls.</p><p>  3. Performing Form Validation with Validation Controls</p><p>  Using Client-side Validation</p><p>  Traditionally, Web developers have fa

63、ced a tough choice when adding form validation logic to their pages. You can add form validation routines to your server-side code, or you can add the validation routines to your client-side code.</p><p>  T

64、he advantage of writing validation logic in client-side 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

65、 error message without requiring a roundtrip back to the server.</p><p>  People really like client-side validation. It looks great and creates a better overall user experience. The problem, however, is that

66、 it does not work with all browsers. Not all browsers support JavaScript, and different versions of browsers support different versions of JavaScript, so client-side validation is never guaranteed to work.</p><

67、;p>  For this reason, in the past, many developers decided to add all their form validation logic exclusively to server-side code. Because server-side code functions correctly with any browser, this course of action w

68、as safer.</p><p>  Fortunately, the Validation controls discussed in this chapter do not force you to make this difficult choice. The Validation controls automatically generate both client-side and server-si

69、de code. If a browser is capable of supporting JavaScript, client-side validation scripts are automatically sent to the browser. If a browser is incapable of supporting JavaScript, the validation routines are automatical

70、ly implemented in server-side code.</p><p>  You should be warned, however, that client-side validation works only with Microsoft Internet Explorer version 4.0 and higher. In particular, the client-side scri

71、pts discussed in this chapter do not work with any version of Netscape Navigator.</p><p>  Requiring Fields: The RequiredFieldValidator Control</p><p>  You use RequiredFieldValidator in a Web f

72、orm 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. </p>

73、;<p>  Validating Expressions: The RegularExpressionValidator Control</p><p>  You can use RegularExpressionValidator to match the value entered into a form field to a regular expression. You can use

74、this control to check whether a user has entered, for example, a valid e-mail address, telephone number, or username or password. Samples of how to use a regular expression to perform all these validation tasks are provi

75、ded in the following sections. </p><p>  Comparing Values: The CompareValidator Control</p><p>  The CompareValidator control performs comparisons between the data entered into a form field and

76、another value. The other value can be a fixed value, such as a particular number, or a value entered into another control. </p><p>  Summarizing Errors: The ValidationSummary Control</p><p>  Im

77、agine 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 ex

78、ample, you might have to scroll down to the 48th form field to find the error message.</p><p>  Fortunately, Microsoft includes a ValidationSummary control with the Validation controls. You can use this cont

79、rol to summarize all the errors at the top of a page, or wherever else you want.</p><p>  4. Advanced Control Programming</p><p>  Working with View State</p><p>  By default, almos

80、t all ASP.NET 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

81、are preserved.</p><p>  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 application variabl

82、es. View state is implemented with a hidden form field called VIEWSTATE that is automatically created in every Web Forms Page.</p><p>  When used wisely, view state can have a dramatic and positive effect on

83、 the performance of your Web site. For example, if you display database data in a control that has view state enabled, you do not have to return to the database each time the page is posted back to the server. You can au

84、tomatically preserve the data within the page's view state between form posts.</p><p>  Displaying and Hiding Content</p><p>  Imagine that you are creating a form with an optional section.

85、For example, imagine that you are creating an online tax form, and you want to display or hide a section that contains questions that apply only to married tax filers.</p><p>  Or, imagine that you want to a

86、dd an additional help button to the tax form. You might want to hide or display detailed instructions for completing form questions depending on a user's preferences.</p><p>  Finally, imagine that you w

87、ant to break the tax form into multiple pages so that a person views only one part of the tax form at a time.</p><p>  In the following sections, you learn about the properties that you can use to hide and d

88、isplay controls in a form. You learn how to use the Visible and Enabled properties with individual controls and groups of controls to hide and display page content.</p><p>  Using the Visible and Enabled Pro

89、perties</p><p>  Every control, including both HTML and Web controls, has a Visible property that determines whether the control is rendered. When a control's Visible property has the value False, the co

90、ntrol is not displayed on the page; the control is not processed for either pre-rendering or rendering.</p><p>  Web controls (but not every HTML control) have an additional property named Enabled. When Enab

91、led has the value False and you are using Internet Explorer version 4.0 or higher, the control appears ghosted and no longer functions. When used with other browsers, such as Netscape Navigator, the control might not app

92、ear ghosted, but it does not function.</p><p>  Disabling View State</p><p>  In certain circumstances, you might want to disable view state for an individual control or for an ASP.NET page as a

93、 whole. For example, you might have a control that contains a lot of data (imagine a RadioButtonList control with 1,000 options). You might not want to load the data into the hidden __VIEWSTATE form field if you are worr

94、ied that the form data would significantly slow down the rendering of the page.</p><p>  Using Rich Controls</p><p>  In the following sections, you learn how to use three of the more feature-ri

95、ch controls in the ASP.NET framework. You learn how to use the Calendar control to display interactive calendars, the AdRotator control to display rotating banner advertisements, and the HTMLInputFile control to accept f

96、ile uploads.</p><p>  ASP.NET 技術(shù)</p><p>  1.構(gòu)建 ASP.NET 頁面</p><p>  ASP.NET 和ASP.NET結(jié)構(gòu)</p><p>  ASP.NET 是微軟.NET framework整體的一部分, 它包含一組大量的編程用的類,滿足各種編程需要。 在下列的二個部分中, 你如何學會

97、 ASP.NET 很適合的放在.NET framework, 和學會能在你的 ASP.NET 頁面中使用語言。</p><p><b>  .NET類庫</b></p><p>  假想你是微軟。 假想你必須支持大量的編程語言-比如 Visual Basic 、 JScript 和 C++. 這些編程語言的很多功能具有重疊性。 舉例來說,對于每一種語言,你必須包括存取

98、文件系統(tǒng)、與數(shù)據(jù)庫協(xié)同工作和操作字符串的方法。</p><p>  此外,這些語言包含相似的編程構(gòu)造。 每種語言,舉例來說,都能夠使用循環(huán)語句和條件語句。 即使用 Visual Basic 寫的條件語句的語法不與 用C++ 寫的不一樣,程序的功能也是相同的。</p><p>  最后,大多數(shù)的編程語言有相似的數(shù)據(jù)變量類型。 以大多數(shù)的語言,你有設(shè)定字符串類型和整型數(shù)據(jù)類型的方法。舉例來說,

99、 整型數(shù)據(jù)最大值和最小值可能依賴語言的種類,但是基本的數(shù)據(jù)類型是相同的。</p><p>  對于多種語言來說維持這一功能需要很大的工作量。 為什么繼續(xù)再創(chuàng)輪子? 對所有的語言創(chuàng)建這種功能一次,然后把這個功能用在每一種語言中豈不是更容易。</p><p>  .NET類庫不完全是那樣。 它含有大量的滿足編程需要的類。舉例來說,.NET類庫包含處理數(shù)據(jù)庫訪問的類和文件協(xié)同工作,操作文本和生成

100、圖像。 除此之外,它包含更多特殊的類用在正則表達式和處理Web協(xié)議。</p><p>  .NET framework,此外包含支持所有的基本變量數(shù)據(jù)類型的類,比如:字符串、整型、字節(jié)型、字符型和數(shù)組。</p><p>  最重要地, 寫這一本書的目的, .NET類庫包含構(gòu)建的 ASP.NET 頁面的類。然而你需要了解當你構(gòu)建.NET頁面的時候能夠訪問.NET framework 的任意類

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論