McGraw-Hill © 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 9 Web Applications.

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

DT228/3 Web Development WWW and Client server model.
Understand Web Page Development Software Development Fundamentals LESSON 4.1.
Project 1 Introduction to HTML.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
1 Chapter 12 Working With Access 2000 on the Internet.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 1.1 of…
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
Tutorial 3: Adding and Formatting Text. 2 Objectives Session 3.1 Type text into a page Copy text from a document and paste it into a page Check for spelling.
Creating Web Page Forms
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Getting Started with Dreamweaver
Chapter 9 Web Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
 Using Microsoft Expression Web you can: › Create Web pages and Web sites › Set what you site will look like as you design it › Add text, images, multimedia.
INTRODUCTION TO WEB DATABASE PROGRAMMING
Introduction to.Net and ASP.Net Course Introduction Build Your Own ASP.Net Website: Chapter 1 Microsoft ASP.Net Walkthrough: Creating a Basic Web Forms.
Chapter 4 Dreamweaver: Part II The Web Warrior Guide to Web Design Technologies.
9-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
McGraw-Hill © 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 9 Web Applications.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
Copyright © cs-tutorial.com. Introduction to Web Development In 1990 and 1991,Tim Berners-Lee created the World Wide Web at the European Laboratory for.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Object-Oriented Application Development Using VB.NET 1 Chapter 12 Web Forms, HTML, and ASP.NET.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
16-1 The World Wide Web The Web An infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that information.
Tutorial 1 Getting Started with Adobe Dreamweaver CS3
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Creating Web Applications Using ASP.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
Chapter 9 Programming with Web Forms Programming In Visual Basic.NET.
ASP.NET Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
NASRULLAH KHAN.  Lecturer : Nasrullah   Website :
XP Dreamweaver 8.0 Tutorial 3 1 Adding Text and Formatting Text with CSS Styles.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
HTML, XHTML, and CSS Sixth Edition Chapter 1 Introduction to HTML, XHTML, and CSS.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Session 1 SESSION 1 Working with Dreamweaver 8.0.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Programming with Visual Web Developer Chapter 9.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
Tutorial 3 Adding and Formatting Text with CSS Styles.
Chapter 1 Getting Started With Dreamweaver. Exploring the Dreamweaver Workspace The Dreamweaver workspace is where you can find all the tools to create.
Understanding Web Applications Lesson 4. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Web Page Development Understand Web.
Introduction to HTML. _______________________________________________________________________________________________________________ 2 Outline Key issues.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
HTML Concepts and Techniques Fifth Edition Chapter 1 Introduction to HTML.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Chapter 1 Introduction to HTML, XHTML, and CSS HTML5 & CSS 7 th Edition.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Static and Dynamic Web Pages
Chapter 9 Programming with Web Forms
Presentation transcript:

McGraw-Hill © 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 9 Web Applications

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved. 9-2 Chapter Objectives - 1 Explain the functions of the server and the client in Web programming Create a Web Form and run it in a browser Describe the differences among the various types of Web controls and the relationship of Web controls to controls used on Windows forms Understand the event structure required for Web programs Design a Web Form using tables

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved. 9-3 Chapter Objectives - 2 Control the styles used on Web pages using cascading style sheets (CSS) Create multiple pages in a Web application Navigate using the HyperLink control and the Server object Validate Web input using the validator controls Use state management to preserve values in variables Use AJAX to update a portion of a Web page Define ASP.NET, XML, WSDL, and SOAP

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved What Are Active Server Pages? Web server based technology, a tool for building Web applications ASP (Not Application Service Provider) A powerful framework that provides dynamic generation of Web pages Facilitates access to information from other sources such as databases Requires Web server that has ASP installed as an extension Combination of HTML and executable codes that allows programming logic to be embedded within a Web page

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved. 9-5 AIU ITP Servlets 5 The Original Web Model HTTP REQUEST User’s Browser Web Server HTML Web Page (.htm)

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved. 9-6 The Dynamic Web Model HTTP REQUEST User’s BrowserWeb Server Engine: reads user’s request ; generates Web page HTML The Web page to be delivered to the client is generated “ on the fly “ as the result of the server-side processing of the “page draft” – the Active Server Page, and the result of this processing will be delivered to the client

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Why Build Web Pages Dynamically? The Web page is based on data submitted by the user –E.g., results page from search engines and order- confirmation pages at on-line stores The Web page is derived from data that changes frequently –E.g., a weather report or news headlines page The Web page uses information from databases or other server-side sources –E.g., an e-commerce site could use a servlet to build a Web page that lists the current price and availability of each item that is for sale.

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved ASP’s Job – Communicate with Web Client Read explicit data sent by client (form data) Read implicit data sent by client (request headers) Generate the results Send the explicit data back to client (HTML) Send the implicit data to client (status codes and response headers) Can a client sent any data to the server ? Why ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved CGI (Common Gateway Interface) : –an extension to Web server application –CGI allowed Web sites to dynamically create Web pages from a program running on a server and typically written in C or a scripting language such as Perl –CGI added functionality to the Web –CGI programs often exhausted memory space on Windows computers –These shortcomings eventually led to Active Server Pages, or ASP from Microsoft, and Servlets and JSP from Sun used now First Tool to make Web Dynamic was : CGI

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved What is an Active Server Page ? a server-side component Runs (being processed by a ASP container (IIS) Hosted on the IIS Web server ASP can be used to Create HTML pages on the fly Perform CGI related task to facilitate HTTP communications between a client and a server Access any business classes at the server Use distributed objects, access databases, systems, legacy systems Perform many other services

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved AIU ITP Servlets 11 Scripting Client Side vs. Server Side Client side scripts are embedded in a Web page and interpreted by the browser Server side codes are embedded in a Web page ( or stand behind it ) and interpreted by the Web server (the browser never sees them) Core language plus environment’s objects provide a powerful tool for creating Web applications

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved ASP.NET Main ASP.NET applications 1.Web Forms Used to process forms and develop cross- browser applications Uses.aspx file extension 2.Web Services Other applications can interact with your program Uses.asmx file extension

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved ASP.NET ASP.NET 3.5 is the latest Web programming technology from Microsoft ASP.NET provides libraries, controls, and programming support for programs that: –Interact with the user –Maintain state –Render controls –Display data –Generate appropriate HTML Write object-oriented, event-driven Web applications using C# and ASP.NET Where is ASP.NET application deployed ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved C# and Web Programming Web Forms are used to create the user interface for Web applications A Web Form displays as a document in a browser You can create documents that display on mobile devices, such as cell phones and PDAs (using the Standard Edition and above) Where is the Web Form hosted ? Where is it processed ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved C# and ASP.NET Each Web Form has two distinct pieces –HTML and instructions needed to render the page –C# code A Web Form generates two files: –.aspx extension for the HTML –.aspx.cs extension for the C# code Holds the logic to respond to events Called the "code behind" file C# code is not compiled into an.exe file, it is compiled into a dynamic link library (dll) file

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Web Servers To develop Web applications –Use a remote Web server –Make your local machine a Web server Visual Studio Web Server –Installs automatically with Visual Web Developer or Visual Studio –Simplifies development, testing, and debugging –Use IDE tools to transfer application to an IIS Web server after development to share with others Internet Information Services (IIS)

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Web Clients Browsers display pages written in a markup language such as HTML or XHTML Pages may also contain program logic –Script JavaScript, VBScript, JScript –Java applets Programming for a network intranet –Users’ browser is known Programming for the Internet –Test and check output on multiple browsers Internet Explorer, Mozilla FireFox and Opera Is there any difference between HTML and XHTML ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Web Pages Web pages are stateless –The page does not store any information about its contents from one invocation to the next Techniques for working around the stateless limitation –Storing cookies on the local machine –Sending state information to the server as part of the page's address, called the uniform resource locator (URL) The server can send the state information back with the next version of the page What is a cookie ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Types of Web Sites Web applications are referred to as Web sites in VS 2008 Four types of Web sites : 1.File System 2.Local IIS 3.FTP site 4.Remote site

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved File System Web Sites Store Web pages and associated files in any folder on the local computer or on the network Does not expose the computer to security vulnerabilities Does not require administrative rights to create and debug a Web project Runs on Home Edition of Vista or XP

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved IIS Web Sites IIS on a local computer hosts a Web server that must be secured Requires administrative rights on the computer to create IIS Web projects By default files are stored in C:\inetpub\wwwroot folder –A virtual IIS directory can be created to store a Web site What is a vituall IIS directory ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Remote Sites and FTP Sites Administrative rights on the host computer must be granted to do development on a remote Web server FTP cannot be used to create a new Web site A previously created FTP Web site can be opened in Visual Studio : – you can do development on a remote server MS Azure platform – have a look what it is …

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Creating a Web Site Select New Web Site from the File menu In the New Web Site dialog box, select the template, location, and language Give the Web site a name by appending the name to the location

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Web Page Files A new Web site automatically contains one Web page, Default.aspx –Visual representation of the page (HTML tags) A second file, Default.aspx.cs, holds the C# code for the page ASP.NET has a second model for Web applications—single-file model –Stores all HTML, control definitions, and code in one single file The textbook teaches the code-separation model that uses two separate files

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Web Forms in the Visual Studio IDE Differences between a Web application and a Windows Forms application –Web Form (page or document) not a Windows Form –Toolbar –List of files in the Solution Explorer –Toolbox has different controls Properties and events different than controls that have a Windows counterpart Views available in the IDE are Design, Source (HTML or ASP.NET) or a Split window How do a Windows Form and Web Form differ ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Viewing the HTML Code Three tabs at bottom of Web Form –Design –Split Splits the Document window horizontally to see both the design and source –Source Static HTML code

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Controls - 1 Several types of controls available for Web Forms –Standard (ASP.NET server controls)—Richest and most powerful controls provided by ASP.NET and.NET framework –Data—Display database data –Validation—Validate user input before it is sent to server –Navigation—Includes the Menu control –Login—Login controls and wizards –WebParts—Change the appearance and behavior of the interface from the browser

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Controls - 2 –AJAX Extensions – Provide for faster Web page loading and richer interfaces –HTML – Standard elements that operate only on the client HTML controls pass to and from the server as static text –Others – Depending on version of VS, other sections may be available (i.e. Reporting)

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Controls - 3 In Design view, client-side HTML controls and ASP server controls are different Popup DataTips identify the type of control and its ID (Name)

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Event Handling Write C# code for events of Web controls in the same way as for Windows controls Events may occur on either the client or server The process of capturing an event, sending it to the server, and executing the required methods is all done automatically Events of Web Forms and controls are different than for Windows Forms –Examples Page.Load versus Form.Load Button control has much shorter list of events for a Web Form versus a Windows From

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved One more time : Page Files Web application files differ greatly from a Windows application aspx file –Holds specifications for the user interface used by the server to render pages aspx.cs file –Code-behind file for the aspx file

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Testing in Other Browsers To test in another browser, in the Solution Explorer: –Right-click on the project name –Select Browse With –Select from browsers installed on the computer Why would you need/like to test in another browser ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Laying Out Web Forms Factors that will affect the layout of page –Browsers –Screen sizes –Screen resolutions ASP.NET generates appropriate HTML to render the page in various browsers but cannot be aware of the screen size, resolution, or window size on the target machine

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using Tables for Layout HTML tables contain rows and columns and allow control over placement of elements on a Web page Add controls and text to the table cells to align the columns A table is an HTML control, which requires no server-side programming Does it mean that you need to use tables on every page ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Placing Controls or Text in a Table - 1 Add controls to any table cell or type text in a cell during design time –To refer to the text in a cell at run time, add a label and give it an ID or type text directly into the cell –Merge cells to allow room for a title or a larger image

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Placing Controls or Text in a Table - 2 Table borders show at design time but not at run time Hoe to make tables seen at the run time ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Absolute Positioning Places controls in a specific X and Y position –Controls may not show up if user has set browser window to small size –Controls may overlap if the user has selected a large font size for the browser window Controls can be dragged using the white tab at the top of a selected control Controls remain in the same position relative to the Web page As from the above : does absolute positioning have a value ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Including Images on Web Pages - 1 Use the Image control to add graphics to a Web page –Concept is similar to the PictureBox on Windows Forms, but the graphic file is connected differently due to the nature of Web applications Each Image control has an ImageUrl property that specifies the location of the graphic file –Best to first copy the graphic into the Web site folder - WHY ? Add an Image control to a cell in a table or directly on a Web page

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Including Images on Web Pages - 2 Web page table has three rows and three columns –Image and company title are in first row, textbox is in second row, hyperlink is in last row

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Cascading Style Sheets New tools for using styles in Web applications are called Expression Web –Expands, enhances and simplifies using cascading style sheets (CSS) Use CSS to create, modify and apply styles to single elements on a page, an entire page, all pages, or all applications of an organization What do we mean by style ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using Styles - 1 Styles are rules that specify page layout, position, font, color, alignment, margins, borders, background and bullet and numbering formats Create and apply new styles within a page Attach an external.css file to apply styles Save styles to an external.css file for use on other pages or Web sites

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using Styles - 2 Styles can be defined in several locations –Web page – inline style For elements that appear only once on a page –style section – page style For elements that may be used in more than one location on a page –external style sheet -.css file For elements that may appear on more than one page or in multiple Web sites How to add external CSS to a Web project ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using Styles - 3 “Cascading” refers to the order of precedence of the style rules For example –Style sheet (global) sets font, color, size, alignment –Local (page-defined) style for the color and size takes precedence (font and alignment still in effect from style sheet) –Inline (more local) style for the size takes precedence over local and style sheet (color from local and font and alignment from style sheet remain)

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Types of Styles Several new tools are available to define, apply, modify and change the location of styles –Apply Styles window : see Styles menu –Manage Styles window : View -> “Manage Styles” –Use the icons in the CSS Style Types table to identify the various types of styles

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Defining Styles Define a new style in the New Style dialog box Choose the category and make settings –For example Font Block –Text-align, text-indent, vertical align List –Bullet and numbering attributes Table –Borders and spacing

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Managing Styles In the Manage Styles Window, preview each style –Drag styles from one category to another to change the location of the style definition A style created in the current page can be moved to a.css file to allow its use in other pages In the CSS Properties window see the settings for a given style

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Navigating Web Pages ASP.NET provides several techniques to navigate from one Web page to another Easiest form of navigation is to use a HyperLink control

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Linear and Hypertext Documents

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using Hyperlinks Add a HyperLink control to allow the user to navigate to another page or another site Set properties of the HyperLink control –Text—Text to display for the user –NavigateUrl—Specify the URL to which to navigate For another Web site, type the Web address (URL) For another page in the application, use the Select URL dialog box and select the page from a list

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Adding a Second Web Page Add a new web form to the project Add controls to the new page Add a HyperLink to the Main Page Set the Start Page Run the application, test the links

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Transferring Pages in Code At times a hyperlink cannot be used because some other action in code needs to be performed prior to the transfer Transfer to another page in code –Use the Server.Transfer method Server.Transfer (“Offer.aspx”);

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using the Validator Controls - 1 ASP.NET provides several validator controls that can automatically validate input –Add a validator control –Attach it to an input control (such as a text box) –Set the error message to display At run time, when the user inputs data, the error message displays if the validation rule is violated Validator controls run on the client-side How did they do without MS Validator controls ? Can it be done in code ? What language?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using the Validator Controls - 2 A blank entry passes the validation for each of the controls except the RequiredFieldValidator –To ensure a field is not blank and it passes a range check attach both a RangeValidator and a RequiredFieldValidator to the field Enter a complete message in the ErrorMessage property or set the property to an asterisk

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using the Validator Controls - 3 Validator Controls RequiredFieldValidatorRequires that the user enter something into the field CompareValidatorCompares the value in the field to the value in another control or to a constant. Also can be used to verify that the input value can be converted to the correct data type RangeValidatorRequires that the input value falls in the specified range RegularExpressionValidatorValidates against a regular expression, similar to the mask in a masked text box ValidationSummaryDisplays a summary of all of the messages from the validator controls

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Maintaining State Web pages hold static data Each time a page is displayed or redisplayed it is a fresh copy Each time the page is posted back to the server a new copy of the program is loaded Steps must be taken to maintain the state of the page –Otherwise the values of variables and controls on the page will be lost in every postback

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Retaining the Contents of Controls ASP.NET can retain and redisplay control contents Web controls have an EnableViewState property –Set to true by default –Indicates to the server to send the control’s contents back with the page

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Retaining the Values of Variables - 1 Local variables work the same in a Web or Windows application Class-level variables are lost unless steps are taken to save them Store the value of a class-level variable in a control on a Web page –EnableViewState property holds the value during postback

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Retaining the Values of Variables - 2 Set up a control with its Visible property set to false or use the HiddenField control Assign the class-level variable to the invisible control –For a hidden field, use the (string) Value property // Declare a class level variable. private decimal discountTotalDecimal; protected void submitButton_Click(object sender, EventArgs e) { //... Calculations omitted. discountHiddenField.Value = discountTotalDecimal.ToString(); }

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Checking for Postback The Page_Load event occurs many times (during each postback) in a Web application IsPostBack property is set to false for an initial page load and true for all page loads following the first Test for IsPostBack == false to perform initialization tasks Test for IsPostBack == true to perform tasks only on postback

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Passing Values to a Second Page A HiddenField control maintains the value of a class-level variable for a single page Send information to a second page –Use the Session variable technique to pass data between pages

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using a Session Variable - 1 One instance of the Session object exists for each user of an application –Use to store information about the user on the server –Each time a user accesses an application, a Session object is created with a unique SessionID –Session values are maintained as long as the session exists Sessions can time out, terminate or users can logout Can you get to the same session if you have closed a bropwser and opened it again ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using a Session Variable - 2 Drawbacks to session objects –Information is stored on server Large amounts of data for multiple users can bog down the server –Web sites split server loads among several systems (Web Farm) State information might be on a different server than where the postback originates –.NET handles this problem by specifying the name of the machine that stores the session values in the Web.config file

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Using a Session Variable - 3 Use the Contents collection of the Session object to store values in code Each item in the collection is a key/value pair –Make up a name (the key) and assign a value Clear all session variables by using the Session.Clear method

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved AJAX -1 Create interactive Web applications with Asynchronous JavaScript and XML (AJAX) AJAX allows reloading of only a portion of a Web page on each postback –Only the portion of a page that changes is downloaded and rendered Dramatically increases loading speed AJAX is an open and cross-platform technology

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved AJAX - 2 AJAX pages must include a ScriptManager component (in the toolbox under AJAX Extensions) –Add other controls such as the UpdatePanel A container for other controls –Placing controls inside an UpdatePanel determines which portion of the page updates on a postback The area outside the UpdatePanel remains unchanged

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Some Web Acronyms - 1 XML Extensible Markup Language. –This popular tag-based notation is used to define data and their format and transmit the data over the Web. XML is entirely text based, does not follow any one manufacturer’s specifications, and can pass through firewalls. SOAP Simple Object Access Protocol. –An XML-based protocol for exchanging component information among distributed systems of many different types. Since it is based on XML, its messages can pass through network firewalls.

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Some Web Acronyms - 2 HTTP HyperText Transfer Protocol. –The protocol used to send and receive Web pages over the Internet using standardized request and response messages. Web Service –Code in classes used to provide middle-tier services over the Internet. WSDL Web Services Description Language. –An XML document using specific syntax that defines how a Web service behaves and how clients interact with the service.

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Happy New Year! Happy New Year What do you see here ?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved When Communicating Information/Data: Information/data content Language / media of presentation Form of presentation : phone, TV, Web page, chat,... XML : an attempt to filter out “pure information/data” separate information content and its presentation

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved XML – eXtensible Markup Language What is it? –World Wide Web Consortium (W3C specification) –Describes semantic structure of text documents –Descendant of Standardized General Markup Language (SGML) Complex metalanguage used in technical documentation –Extension of Hypertext Markup Language (HTML)

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved XML code segment Sample of an XML file XML is cool

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved XML – Characteristics XML is for data –Neutral, generic format –Extensible (can create infinite number of tags) –Flexible –Self documenting (human and machine readable) –Simple, easy to use –Separates style from structure

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved To build data : XML Hierarchy Document Unit Sub-unit Document Unit Sub-unit All elements must be nested XML can be described in a tree hierarchy Parent Child Sibling

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved XML Technologies

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved XSL  XSL Transformations (XSLT)  Is a language for transforming XML documents  XSLT stylesheets  Stylesheets format XML documents  Use XSLT to interact with an XML document  Can format individual or groups of elements within the XML document  A form of XSL that transforms the XML data using processing rules in the XSLT stylesheet

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved XSL – Universal Presentation of XML Data : How does it work? Binding XML to existing Web pages is fine, but limited way to present XML data; CSS helps, but has its own language; change style – need another CSS Universal and flexible way : create separate XSL file, which defines how to present every element of XML data, merge them together and create HTML page as a result ; both XML and XSL files can be edited in code XML document XSL document XSL processor HTML Page

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved inventory.xsd

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved XML ASP/ Database : Hot Stuff Typical Web Application now is a 3-tier architecture: We want to create such an application with XML as a data trasfer media : – RS requested according to SQL from any relational DB to be converted to XML –XML at ASP server saved to a file and sent to a Client –XML at Client modified/created, sent to ASP server, validated/processed, data sent to DB for update Web Client ASP Server DataBase Server XML Recordset

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Quiz Explain the differences between the execution of a Windows application and a Web application. Differentiate between the client and the server for a Web application : what is running on a client and what is running at the server ? What is meant by the statement that Web pages are stateless? What are the differences between HTML controls and standard ASP controls? How does event handling differ from that for Windows applications?

McGraw-Hill© 2010 The McGraw-Hill Companies, Inc. All rights reserved Quiz ( cont.) Describe the purpose and functionality of AJAX. What is meant by open standards? What is a Session object and how would it be used? What is the purpose of XML? of SOAP?