Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2004 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Programming the Web Using ASP.Net Chapter 2: The ASP.Net Template Dave.

Similar presentations

Presentation on theme: "© 2004 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Programming the Web Using ASP.Net Chapter 2: The ASP.Net Template Dave."— Presentation transcript:

1 © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Programming the Web Using ASP.Net Chapter 2: The ASP.Net Template Dave Mercer

2 2-2 Objectives 1.Explain the logical difference between Web applications and Web Services 2.Use the ASP.Net template to create a VB.Net project in VS.Net 3.Work with the Solution Explorer to navigate project files 4.Describe the functions of ASP.Net template files 5.Work with the Styles.css file 6.Add and Delete files from the project 7.Describe what ASP.Net Directives are 8.Explain what ASP.Net Directives do 9.Modify ASP.Net Directives in an ASP.Net file 10.Describe how ASP.Net Server controls are coded in a Web form

3 2-3 The ASP.Net Web Application Template Using an IDE such as Visual Studio.Net (VS.Net) speeds up the process of writing ASP.Net documents. One way VS.Net speeds up this process is by providing project templates for these applications, as well as for other commonly programmed items (such as Windows applications and Web Services).

4 2-4.NET Structures and Languages The.Net Framework has many interfaces and classes built-in, and also has the Common Language Runtime to process applications made from the interfaces and classes. The Common Language Runtime (CLR), supported communications protocols, built-in application objects and classes, and support for a number of popular programming languages are what makes the.Net Framework an effective platform for Windows and Web applications

5 2-5 The Common Language Runtime (CLR) The Common Language Runtime (CLR) provides a managed execution environment in which multiple languages can be used to write the various parts of an application. It also provides exception handling across those languages, memory management, thread management, better security, and versioning, deployment, debugging, and profiling services. Appropriate languages include Visual Basic.Net and C# (a managed version of C++).

6 2-6 Microsoft Intermediate Language Specification (MSIL) Code compiled for the CLR is compiled into MSIL. MSIL is a set of instructions that can be efficiently turned into code native to whatever CPU it runs on. MSIL is not dependent upon a particular CPU, and is therefore much more portable than traditionally compiled code. Once on the machine it runs on, MSIL is turned into native code by a Just-In-Time compiler.

7 2-7 Migrating from ASP to ASP.Net Typical ASP documents include ASP and some scripting language code (often VBScript) embedded within HTML code. Web pages are created as though a normal Web page is the intended outcome, but programmers add ASP to standard design templates so that what the user sees in the browser varies dynamically. Many application-style actions are available, such as redirection to another page, but the user’s browser receives only the finished product.

8 2-8 Differences Between ASP and ASP.Net: Using ASP.Net Server Controls One of your first steps in migrating from an ASP application would be to rebuild the basic pages and separate out programming code from HTML (or XHTML) code. Programming code would be inserted into event handlers in the codebehind page, while display code would be left in a file with an extension of.aspx rather than.asp. You can also substitute ASP.Net Server controls for the old-fashioned HTML controls.

9 2-9 Differences Between ASP and ASP.Net: Using Page Directives Another change is in the way page directives are handled. In ASP, you might find a few lines at the top of the page that resemble the following: Change this to:

10 2-10 Differences Between ASP and ASP.Net: VB.Net Syntax There are differences in the way certain arguments are expressed for functions and methods in ASP and ASP.Net. For example, it is permissible to write a response in ASP as follows: Response.write "This is my message" In ASP.Net, the response must be written: Response.write("This is my message") All arguments must be properly enclosed in parentheses.

11 2-11 Differences Between ASP and ASP.Net: Variable Declaration and Data Types In ASP, using VBScript, variables are not required to be declared. If you begin to use variables without declaring them first they are simply used, and no data type is required. In ASP, values are assigned a data type of “Variant,” which no longer exists in ASP.Net and VB.Net). In ASP.Net, you’ll need to identify all variables and specifically declare them with the appropriate data type.

12 2-12 Project, Templates, and Template files Project Types Such As: Visual Basic Projects C# Projects Template Types Such As: ASP.Net Web Applications ASP.Net Web Services Project Types Such As: Global.asax C# Projects

13 2-13 Creating a New Project in ASP.Net

14 2-14 References A project’s References node contains: –System –System.Data –System.Drawing –System.Web, and –System.XML. Each reference name refers to a.Net Framework namespace that contains fundamental and base classes and interfaces that support Web-based communications, events and event handlers, data and graphics processing, and XML processing.

15 2-15 References (2) Each reference has a “Name” attribute and an “AssemblyName” attribute. These references refer to assemblies that are included in the Global Assembly Cache. –The global assembly cache is a machine-wide code cache that stores assemblies meant to be shared by multiple applications on the computer (for example, on the server running your Web application).

16 2-16 The bin Folder The “bin” folder contains your Dynamic Link Library (.dll) file and your Program Debug Database (.pdb) files. –The DLL file contains a library of classes created from your Web forms and controls when the project is built (or compiled). –The PDB file contains debug information that is created when you build your application in debug mode.

17 2-17 The AssemblyInfo.vb File When you create a project in a solution with Visual Studio.Net, you are creating an assembly. Assemblies form a logical unit that can include security, version, type, and other pertinent information. Assembly attributes include the following types: identity, informational, manifest, and strong name. Each attribute has a specific name. Some are defined automatically while others can be set by the developer.

18 2-18 The Global.asax File The global.asax file is an optional file, but is highly useful in ASP.Net Web applications. It contains code for responding to application and session events. The term application event means an event that happens to the entire application. The Global.asax.resx file is used to store data that does not change, such as error messages. This simplifies changing this data content without affecting the rest of the application.

19 2-19 The Styles.css File The Styles.css file contains data for Cascading Style Sheets styles. Cascading Style Sheets (CSS) is actually a language for specifying elements and setting the properties of these elements globally or individually by defining values for them. Elements and the property values assigned to them are specified in CSS as a selector and a declaration. A single stylesheet file can be linked to all Web pages in an application.

20 2-20 The Web.config File ASP.Net Web applications can be configured with specialized configuration files. The Web.config file is formatted as an XML file. The first element is “configuration” and all other elements in the document are contained within this element. If you are using VS.Net to develop your application, the Web.config file will be edited for you when you change settings (such as turning off debug mode).

21 2-21 The WebAppStructure.vsdisco File Files ending in.vsdisco are for making discovery of Web Services possible. These files are formatted as XML documents, and included by default in ASP.Net Web Applications even though they are for discovering XML Web Services. These files are included because many of the Web applications you create will include Web Services.

22 2-22 WebForm Files The WebForm1.aspx file contains HTML and XML elements making up the rendered display in the user’s browser. The WebForm1.aspx.vb file is called the “codebehind” file. It contains the code that runs when controls on your form respond to events. The WebForm1.aspx.resx file is used to store resources applicable to the Web form.

23 2-23 ASP.Net Page Processing The.Net Framework provides classes from which objects can be derived for Windows and Web applications, among other programmed structures. ASP.Net provides not only classes from which objects useful for Web applications can be derived, but is also a complete Web platform for any Web application you develop. You can use any language you like that is compatible with the Common Language Runtime (CLR).

24 2-24 ASP.Net Page Processing (2) The ASP.Net page framework is the Web server architecture that dynamically produces and manages Web forms. The ASP.Net page framework automatically maintains the state of the page and its controls. Unlike ASP, ASP.Net pages typically use two files to contain the display code and the programming code. The file extensions for these pages are.aspx and.aspx.vb (or.aspx.cs with C#).

25 2-25 The ASP.Net Compilation Process Files containing code-behind classes are all compiled into a dynamic-link library or.dll file for the project they are a part of. The first time a user requests an.aspx page in your Web application, a.Net class file is automatically generated from that page and then compiled into a second.dll file that inherits from the overall.dll file. Thereafter, any call to that page is responded to by the application running as an executable program.

26 2-26 Page Processing The basic class in an ASP.Net Web application is the page class. A Web forms page goes through a series of page processing steps every time it is requested: initialize, process, and dispose. A special stage called render is performed towards the end of the processing cycle, and it is during this stage that the HTML output is created.

27 2-27 ASP.Net Directives ASP.Net Directives are settings used when a page or control is compiled. The actual page browsed to by the user is compiled dynamically, and the @ Page directive contains an attribute (named Inherits) that defines the class from which the.aspx file derives. Although directives can be placed in any location in your file, the traditional place to locate them is at the top of the file.

28 2-28 General Layout of Directives in ASP.Net Files

29 2-29 Coding Directives The @ Page Directive The @ Control Directive The @ Import Directive The @ Implements Directive The @ Register Directive The @ Assembly Directive The @ Output Cache Directive The @ Reference Directive

30 2-30 The End

Download ppt "© 2004 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Programming the Web Using ASP.Net Chapter 2: The ASP.Net Template Dave."

Similar presentations

Ads by Google