Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASP.NET Part I Dr. Awad Khalil Computer Science Department AUC.

Similar presentations


Presentation on theme: "ASP.NET Part I Dr. Awad Khalil Computer Science Department AUC."— Presentation transcript:

1 ASP.NET Part I Dr. Awad Khalil Computer Science Department AUC

2 ASP.NET Content Introduction.NET Overview.NET Framework ASP (Active Server Pages).NET Setup JScript.NET A Simple ASP.NET Example Web Forms Session Tracking Cookies Session Tracking with HttpSessionState ASP.NET and XML Reading and Writing Text Files Connecting to a Database in ASP.NET Code-Behind Approach ASP.NET Web Services Web Resources

3 Objectives In this topic, you will learn: –To program ASP.NET pages using JScript.NET. –To understand how ASP.NET pages work. –To understand the differences between client-side scripting and server-side scripting. –To create Web services. –To use and manipulate XML files with ASP.NET. –To understand Web forms and code-behind files. –To be able to use session tracking in an ASP.NET application. –To use ActiveX Data Objects.NET (ADO.NET) to access a database.

4 Introduction ASP.NET –Server-side technology that dynamically builds documents in response to client requests. –Can be used on a server to create Web applications. –Supports over 25 programming languages. –ASP.NET takes advantage of.NET Framework, which provides thousands of classes that deal with XML, text input, validation of user input, image processing, and more. –ASP.NET also simplifies Web Services programming. –Object-oriented programming.

5 .NET Overview Independent from a specific programming language. Programmers can contribute to the same application, writing the code in any.NET-compatible languages (such as VB.NET, Visual C++.NET, and C#). Promotes software reuse. Include tools for porting, adapting existing software components. Web services, which are central to.NET initiative, extend the concept of Software reuse to the Internet by allowing developers to reuse software components that reside on another machine or platform. For example, a company developing an e-commerce application can subscribe to Web services that process payments and authenticate users – this enables programmers to focus on other unique aspects of the e- commerce application.

6 .NET Framework The.NET Framework is at the heart of the.NET strategy. It manages and executes applications, provides a class library, enforces security and supplies many other programming capabilities. Framework Class Library ( FCL ) –Enforces security and supplies many other programming capabilities –Reusable components that programmers can incorporate into their applications Common Language Runtime ( CLR ) –Executes programs written in any.NET-compatible programming language.NET Compact Framework.

7 .NET Compact Framework.NET Compact Framework enables developers to create applications for limited- resource devices, such as mobile phones and PDAs. Applications built using the Compact Framework can run on any device that has the Compact Framework installed. Users download applications onto a device through a wireless Internet connection or a connection from a PC. Once downloaded to the device, many applications do not require an Internet connection.

8 Common Language Runtime (CLR) CLR executes programs written in any.NET- compatible programming language..NET programs are compiled in two steps: –First, a program is compiled into Microsoft Intermediate Language ( MSIL ), which defines instructions for the CLR. Code translated into MSIL from multiple programming languages and sources can be woven together by the CLR. –MSIL then is compiled into machine code for a specific platform.

9 ASP (Active Server Pages).NET ASP.NET another integral part of the.NET initiative, is a technology for creating dynamic Web content marked up as HTML. ASP.NET developers can create multi-tier, database- intensive applications quickly by employing.NET’s object-oriented languages and the FCL’s Web controls (technically known as ASP.NET server controls ). Web controls look like HTML elements but are designed specifically for ASP.NET applications. Includes optimizations for performance, testing and security ASPX files XHTML documents –Static

10 ASPX Files ASP.NET applications consist of several file types. The first is.aspx, which we refer to as ASPX files. ASPX files contain the graphical user interface of a page, and may also contain the logic of the page (in the form of scripts written in a.NET- compatible language). These scripts are usually separated from the portion of the ASPX file that defines the page’s GUI. ASPX files often have a corresponding code-behind file that contains a class written in a.NET language, such as JScript.NET. This class includes initialization code, utility methods and other supporting code that provides the ASPX file’s programmatic implementation. Code-behinds help separate the business logic code from the presentation code. Code-behinds written in JScript.NET typically have an.aspx.js extension and are usually used in the middle tier of a three-tier Web- based application.

11 Setup Creating and viewing ASP.NET pages requires:  Microsoft.NET Framework. .NET Framework System Development Kit (SDK), which provides tools, examples, reference files and tutorials building.NET applications.

12 Setup Configuring a virtual directory as an application in IIS.

13 JScript.NET Truly object-oriented language. Backward compatible with JScript. Adheres to ECMA 262 Edition 4 standard. Provides classes, packages, typed variables and access to.NET Framework. Enables programmers to declare the types of variables, for example: var number : int, size : int; var word = StringBuilder() : StringBuilder;

14 A Simple ASP.NET Example Scripting delimiters –Wrapped around JScript.NET code –Compiled and executed on the server –@ Page directive Specifies information needed by CLR to process file –Language attribute Specifies JScript.NET as scripting language –runat attribute with value “server” Indicates script should be processed on server

15 Outline date.aspx (1 of 2)

16 Outline date.aspx (2 of 2)

17 Outline HTML generated by date.aspx (1 of 2)

18 Outline HTML generated by date.aspx (2 of 2)

19 Commonly Used ASP.NET Objects An ASP.NET application when compiled, actually defines a class. The class inherits from class Page, provided by the.NET Framework. By inheriting from the Page class, the ASP.NET application gains access to several built-in objects that enable programmers to communicate with a Web browser, gather data sent by an HTTP request and distinguish between users.

20 Web Forms ASPX files are usually referred to as Web Forms or Web Form Pages because they normally process form input. Data entered into a form can be sent to the server, processed, then sent back to the client in different format. The first time a Web form is requested, the entire page is compiled. Later requests are served from the compiled page and do not have to be recompiled. Technically, any text file with an.aspx extension is an ASP.NET Web Forms page. Any pure HTML page can be given an.aspx extension and run as an ASP.NET page. Programmers customize Web Forms by adding Web controls, which include labels, text boxes,, images, buttons and other GUI components.

21 Web Controls Web controls normally have the attribute runat = “ server ” and are included within an ASP.NET Web Form designated by the tag. There are four types of Web controls: –HTML server controls Programmable HTML elements run on the server –Web server controls Form-like controls such as drop-down lists and text boxes –Validation controls ( validators ) Required field validator Range validator –User controls Created by programmer

22 Web Controls

23

24 Using Basic Web Server Controls The following example is an ASPX page that uses a form element containing server controls,,, and. An ASPX page can contain only one element. ASPX pages usually contain a form that, when submitted causes the current page to be requested again. This event is known as a postback. All the server controls and the form contain the attribute runat = “ server ” to designate that these components should be processed by the server.

25 Outline name.aspx (1 of 3)

26 Outline name.aspx (2 of 3)

27 Outline name.aspx (3 of 3)

28 Using Validators The following example adds validation controls to the name.aspx example. We use a required field validator and a range validator. A required field validator ensures that a field receives input. A range validator checks that input is within a specified range. The RequiredFieldValidator contains the attributes id (which defines the name of the validator control), ControlToValidate (which indicates the control whose input will be validated), Display (which sets the display behavior for the validation control), and runat = “ server ” (which specifies that this control should be processed by the server). Legal Display attribute values are None, Static, and Dynamic. Specifying Static or Dynamic causes the control to display an error message if validation fails.

29 Using Validators Several attributes control the behavior of the RangeValidator : ControlToValidate indicates the id of the server control to validate; MinimumValue specifies the smallest allowed input; MaximumValue specifies the largest allowed input; Type indicates the input’s allowed data type; EnableClientScript is a boolean value that specifies whether client-side validation is enabled or not; Text is the message that is displayed when validation fails; and runat specifies that this control is a server control.

30 Outline validation.aspx (1 of 4)

31 Outline validation.aspx (2 of 4)

32 Outline validation.aspx (3 of 4)

33 Outline validation.aspx (4 of 4)

34 Using Validators Validation error output.

35 Using Validators Validation error output.

36 Using Validators Valid page without validation errors.

37 Using AdRotator Web Control The AdRotator Web control simplifies the creation of advertising banners. The following example uses the AdRotator Web control. Using advertisement data located in an XML file, the AdRotator control randomly selects an image to display, then generates a hyperlink to the Web page associated with that image. Attribute AdvertisementFile specifies an XML file that contains advertisement information (i.e., an image file, URL, alternate text and relative frequency for each ad). The attributes BorderColor and BorderWidth specify the color and width (in pixels), respectively, of the border placed around the displayed banner ad.

38 Outline adRotator.aspx (1 of 4)

39 Outline adRotator.aspx (2 of 4)

40 Outline adRotator.aspx (3 of 4)

41 Outline adRotator.aspx (4 of 4)

42 Outline ads.xml (1 of 2)

43 Outline ads.xml (2 of 2) ASPX page with an AdRotator.


Download ppt "ASP.NET Part I Dr. Awad Khalil Computer Science Department AUC."

Similar presentations


Ads by Google