Presentation is loading. Please wait.

Presentation is loading. Please wait.

 2008 Pearson Education, Inc. All rights reserved. 1 25 ASP.NET 2.0 and ASP.NET Ajax.

Similar presentations


Presentation on theme: " 2008 Pearson Education, Inc. All rights reserved. 1 25 ASP.NET 2.0 and ASP.NET Ajax."— Presentation transcript:

1  2008 Pearson Education, Inc. All rights reserved. 1 25 ASP.NET 2.0 and ASP.NET Ajax

2  2008 Pearson Education, Inc. All rights reserved. 2 25.1 Introduction 25.2 Creating and Running a Simple Web Form Example 25.2.1 Examining an ASPX File 25.2.2 Examining a Code-Behind File 25.2.3 Relationship Between an ASPX File and a Code-Behind File 25.2.4 How the Code in an ASP.NET Web Page Executes 25.2.5 Examining the XHTML Generated by an ASP.NET Application 25.2.6 Building an ASP.NET Web Application 25.3 Web Controls 25.3.1 Text and Graphics Controls 25.3.2 AdRotator Control 25.3.3 Validation Controls

3  2008 Pearson Education, Inc. All rights reserved. 3 25.4 Session Tracking 25.4.1 Cookies 25.4.2 Session Tracking with HttpSessionState 25.5 Case Study: Connecting to a Database in ASP.NET 25.5.1 Building a Web Form That Displays Data from a Database 25.5.2 Modifying the Code-Behind File for the Guestbook Application

4  2008 Pearson Education, Inc. All rights reserved. 4 25.6 Case Study: Secure Books Database Application 25.6.1 Examining the Completed Secure Books Database Application 25.6.2 Creating the Secure Books Database Application 25.7 ASP.NET Ajax 25.8 Wrap-Up 25.9 Web Resources

5  2008 Pearson Education, Inc. All rights reserved. 5 25.1 Introduction  ASP.NET 2.0 and Web Forms and Controls – Web application development with Microsoft’s ASP.NET 2.0 technology – Web Form files have the filename extension.aspx and contain the Web page’s GUI – Every ASPX file created in Visual Studio has a corresponding class written in a.NET language, such as Visual Basic - Contains event handlers, initialization code, utility methods and other supporting code - Called the code-behind file - Provides the ASPX file’s programmatic implementation

6  2008 Pearson Education, Inc. All rights reserved. 6 25.2.1 Examining an ASPX File  Examining an ASPX File – ASP.NET comments begin with – Page directive - Specifies the language of the code-behind file – AutoEventWireup attribute - Determines how Web Form events are handle – Inherits attribute - Specifies the class in the code-behind file from which this ASP.NET class inherits – ASP.NET markup is not case-sensitive, so using a different case is not problematic

7  2008 Pearson Education, Inc. All rights reserved. 7 25.2.1 Examining an ASPX File – runat attribute - Indicates that when a client requests this ASPX file: Process the head element and its nested elements on the server and generate the corresponding XHTML sent to the client – asp: tag prefix in a control declaration - Indicates that it is an ASP.NET Web control - Each Web control maps to a corresponding XHTML element - When processing a Web control, ASP.NET generates XHTML markup that will be sent to the client to represent that control in a Web browser – span element - Contains text that is displayed in a Web page

8  2008 Pearson Education, Inc. All rights reserved. 8 Outline WebTime.aspx ASP.NET comments Page directive to specify information needed by ASP.NET to process this file Document type declaration Mark up of a label web control

9  2007 Pearson Education, Inc. All rights reserved. 9 25.2.2 Examining a Code-Behind File Examining a Code-Behind File – System.Web.UI Contains classes and controls that assist in building Web- based applications Class Page - Provides event handlers and objects necessary for creating Web-based applications - Method Page_Init Handles the Init event Indicates that a page is ready to be initialized Class Control - The base class that provides common functionality for all Web controls

10  2008 Pearson Education, Inc. All rights reserved. 10 Outline WebTime.aspx.vb Retrieves the current time and formats it as hh:mm:ss

11  2007 Pearson Education, Inc. All rights reserved. 11 25.2.3 Relationship Between an ASPX File and a Code-Behind File ASP.NET creates two Partial classes behind the scenes – A class defined in the code-behind file – A class based on the markup in the ASPX file Defines the page’s visual representation Web controls – System.Web.UI.WebControls – Derive from class WebControl

12  2007 Pearson Education, Inc. All rights reserved. 12 25.2.4 How the Code in an ASP.NET Web Page Executes When an instance of a page is created – PreInit event occurs, invoking method Page_PreInit – Init event invokes method Page_Init Used to initalize objects and other aspects of the page – Load event occurs and the Page_Load event handler executes Inherited from class Page – The page processes any events raised by the page’s controls after Page_Load finishes executing – Unload event occurs when a Web Form object is ready for garbage collection Event handler Page_Unload - Inherited from class Page - Contains any code that releases resources

13  2007 Pearson Education, Inc. All rights reserved. 13 25.2.5 Examining the XHTML Generated by an ASP.NET Application XHTML Generated by an ASP.NET Application – XHTML forms can contain visual and nonvisual components – Attribute method Specifies the method by which the Web browser submits the form to the server – Attribute action Identifies the name and location of the resource that will be requested when this form is submitted – The runat attribute is removed when the form is processed on the server The method and action attributes are added The resulting XHTML form is sent to the client browser

14  2008 Pearson Education, Inc. All rights reserved. 14 Outline WebTime.html Declaration for a non-visual component: hidden input Represents the text in the label

15  2007 Pearson Education, Inc. All rights reserved. 15 25.2.6 Building an ASP.NET Web Application Step 1: Creating the Website (Fig. 25.4) – http://localhost (IIS’s root directory) corresponds to C:\InetPub\wwwroot http://localhost Step 2: Examining the Solution Explorer of the Newly Created Project (Fig. 25.5) Step 3: Examining the Toolbox in Visual Web Developer (Fig. 25.6) Step 4: Examining the Web Forms Designer (Fig. 25.7-8) Step 5: Examining the Code-Behind File in the IDE (Fig. 25.9) Step 6: Renaming the ASPX File Step 7: Renaming the Class in the Code-Behind File and Updating the ASPX File Step 8: Changing the Title of the Page

16  2007 Pearson Education, Inc. All rights reserved. 16 25.2.6 Building an ASP.NET Web Application (Cont.) Step 9: Designing the Page (Fig. 25.10) – Relative positioning Positions of controls and other elements are relative to the Web Form’s upper-left corner – Absolute positioning Controls are located exactly where they are dropped on the Web Form – Visual Web Developer is a WYSIWYG editor “What You See Is What You Get” Step 10: Adding Page Logic Step 11: Running the Program – Web.config stores configuration settings for an ASP.NET Web application

17  2008 Pearson Education, Inc. All rights reserved. 17 Fig. 25.11 | WebTime.aspx after adding a Label and setting its properties.

18  2007 Pearson Education, Inc. All rights reserved. 18 25.3.1 Text and Graphics Controls Examining Web Controls on a Sample Registration Form – Image control Inserts an image into a Web page - ImageUrl property specifies the file location of the image to display – TextBox control Allows the you to obtain text from the user and display text to the user – DropDownList control Provides a list of options to the user Each item in the drop-down list is defined by a ListItem element – HyperLink control Adds a hyperlink to a Web page - NavigateUrl property specifies the resource that is requested – RadioButtonList control Provides a series of radio buttons for the user – Button control Represents a button that triggers an action when clicked – Visual Web Developer displays smart tag menus for many ASP.NET controls to facilitate performing common tasks

19  2008 Pearson Education, Inc. All rights reserved. 19 Outline WebControls.aspx (1 of 5) Set the color of a specific piece of text

20  2008 Pearson Education, Inc. All rights reserved. 20 Outline WebControls.aspx (2 of 5) Define a TextBox control used to collect the user’s first name

21  2008 Pearson Education, Inc. All rights reserved. 21 Outline WebControls.aspx (3 of 5) Defines a DropDownList Each item in the drop- down list is defined by a ListItem element Adds a hyperlink to the web page

22  2008 Pearson Education, Inc. All rights reserved. 22 Outline WebControls.aspx (4 of 5) Defines a RadioButtonList control Each item in the drop- down list is defined by a ListItem element Defines a Button web control

23  2007 Pearson Education, Inc. All rights reserved. 23 25.3.2 AdRotator Control AdRotator control – Randomly selects an image to display – Generates a hyperlink to the Web page associated with that image – Browsers that do not support images display alternate text that is specified in the XML document – The browser loads the Web page associated with that image when a user clicks the image or substituted text

24  2007 Pearson Education, Inc. All rights reserved. 24 25.3.2 AdRotator Control (Cont.) AdRotator control – Accesses an XML file to determine what advertisement image, hyperlink URL and alternate text to display and include in the page Create an XmlDataSource control to connect to the XML file – ImageUrl Element Specifies the path (location) of the advertisement’s image – NavigateUrl Element Specifies the URL for the Web page that loads when a user clicks the advertisement - The URL cannot contain any whitespace – AlternateText Element Contains text that displays in place of the image when the browser cannot locate or render the image - Also a tooltip – Impressions Element Specifies how often a particular image appears, relative to the other images

25  2008 Pearson Education, Inc. All rights reserved. 25 Outline FlagRotator.aspx (1 of 2) Defines an AdRotator control Defines an XmlDataSource control, which supplies the data to the AdRotator control

26  2008 Pearson Education, Inc. All rights reserved. 26 Outline AdRotatorInforma tion.xml (1 of 4) Each Ad element represents an advertisement that will be displayed by the AdRotator control Specifies the path of the advertisement’s image Specifies the URL for the Web page that loads when user clicks on the advertisement Text that displays in place of the image when the browser cannot render the image Specifies how often a particular image appears

27  2007 Pearson Education, Inc. All rights reserved. 27 25.3.3 Validation Controls Validation Control – Determines whether the data in another Web control is in the proper format – Provide a mechanism for validating user input on the client – The validator is converted into ECMAScript when the XHTML for the page is created ECMAScript is a scripting language that enhances the functionality and appearance of Web pages For security reasons, validation is always performed on the server

28  2007 Pearson Education, Inc. All rights reserved. 28 25.3.3 Validation Controls (Cont.) – ControlToValidate property Indicates Validator verifies a control’s contents – ErrorMessage Property Text displayed if the validation fails – Display property Determines if the validator is displayed only when validation fails – RegularExpressionValidator Matches a Web control’s content against a regular expression - That expression is assigned to ValidationExpression property – IsPostBack property Determines whether the page is being loaded due to a postback - The current page reloads when the user submits the form EnableViewState attribute – Determines whether a Web control’s state persists when a postback occurs

29  2008 Pearson Education, Inc. All rights reserved. 29 Outline Validation.aspx (1 of 5) Defines a RequiredFieldValidator which confirms the TextBox is not empty

30  2008 Pearson Education, Inc. All rights reserved. 30 Outline Validation.aspx (2 of 5) Defines a RequiredFieldValidator which confirms the TextBox is not empty Defines a RegularExpressionValida tor control to determine whether data is entered in a valid format

31  2008 Pearson Education, Inc. All rights reserved. 31 Outline Validation.aspx (3 of 5) Defines a RequiredFieldValidator which confirms the TextBox is not empty Defines a RegularExpressionValidator control to determine whether data is entered in a valid format

32  2008 Pearson Education, Inc. All rights reserved. 32 Outline Validation.aspx (5 of 5)

33  2008 Pearson Education, Inc. All rights reserved. 33 Outline Validation.aspx.vb Determines whether the page is being loaded due to a postback Retrieves the values of the TextBox es

34  2008 Pearson Education, Inc. All rights reserved. 34 25.4 Session Tracking  Session Tracking – Tracking individual clients – The request/response system on which the Web operates is facilitated by HTTP - HTTP is a stateless protocol Does not support persistent connections  Web servers cannot maintain state information regarding particular clients – A session represents a unique client on a Web site - The client will still be recognized as the same user if the client leaves a site and returns later Each client must identify itself to the server  Help the server distinguish among clients

35  2007 Pearson Education, Inc. All rights reserved. 35 25.4.1 Cookies Cookies – Piece of data stored in a small text file on the user’s computer Maintains information about the client during and between browser sessions – Are sent and received as a collection of type HttpCookieCollection – Web Forms can examine the cookies it sent to the client during previous communications – The expiration date determines how long the cookie remains on the client’s computer The Web browser maintains the cookie for the duration of the browsing session if there is no expiration date – Response object’s Cookies property Used to write cookies to a client Used to access cookies – Can be read by an application only if they were created in the domain in which the application is running

36  2007 Pearson Education, Inc. All rights reserved. 36 25.4.2 Session Tracking with HttpSessionState Class HttpSessionState – Provides session-tracking – Every Web Form includes an HttpSessionState object Accessible through property Session of class Page – Can store name–value pairs using method Add - When adding an attribute that has the same name, the object associated with that attribute is replaced

37  2008 Pearson Education, Inc. All rights reserved. 37 Fig. 25.27 | HttpSessionState properties.

38  2008 Pearson Education, Inc. All rights reserved. 38 Outline Options.aspx (1 of 3)

39  2008 Pearson Education, Inc. All rights reserved. 39 Outline Options.aspx (2 of 3) Hidden labels to display tracking information

40  2008 Pearson Education, Inc. All rights reserved. 40 Options.aspx (3 of 3) Outline

41  2008 Pearson Education, Inc. All rights reserved. 41 Outline Options.aspx.vb (1 of 3)

42  2008 Pearson Education, Inc. All rights reserved. 42 Outline Options.aspx.vb (2 of 3) Returns the unique session ID

43  2008 Pearson Education, Inc. All rights reserved. 43 Outline Options.aspx.vb (3 of 3) Returns the maximum amount of time that an HttpSessionState object can be inactive before it is discarded Place the language and its corresponding ISBN number in the HttpSessionState object

44  2008 Pearson Education, Inc. All rights reserved. 44 Outline Recommendations.aspx (1 of 2) Used to present the recommendations to the user

45  2008 Pearson Education, Inc. All rights reserved. 45 Outline Recommendations.aspx (2 of 2)

46  2008 Pearson Education, Inc. All rights reserved. 46 Outline Recommendations.aspx.vb (1 of 2) Provides the number of session items contained in a Session object Indexes the collection containing all the keys in the session to receive the current key Concatenate and display the string that is the recommendation in the ListBox

47  2008 Pearson Education, Inc. All rights reserved. 47 Outline Recommendations.aspx.vb (2 of 2)

48  2008 Pearson Education, Inc. All rights reserved. 48 25.5.1 Building a Web Form That Displays Data from a Database  Step 1: Creating the Project  Step 2: Creating the Form for User Input (Fig. 25.30)  Step 3: Adding a GridView Control to the Web Form  Step 4: Adding a Database to an ASP.NET Web Application – Database used by an ASP.NET Web site should be located in the project’s App_Data folder  Step 5: Binding the GridView to the Messages Table of the Guestbook Database (Fig. 25.31-34)  Step 6: Modifying the Columns of the Data Source Displayed in the GridView (Fig. 25.35)  Step 7: Modifying the Way the SqlDataSource Control Inserts Data (Fig. 25.36) – Each column is represented as a BoundField

49  2007 Pearson Education, Inc. All rights reserved. 49 25.5.1 Building a Web Form That Displays Data from a Database (Cont.) GridView – DataSourceID property Identifies the data source that is used to fill the GridView with data at runtime – HeaderText property Indicates the text that appears as the column header - By default, this is the name of the column in the data source – Each column is represented as a BoundField

50  2007 Pearson Education, Inc. All rights reserved. 50 25.5.1 Building a Web Form That Displays Data from a Database (Cont.) SqlDataSource – ConnectionString property Indicates the connection that the SqlDataSource control interacts with The value of this property uses an ASP.NET expression, delimited by – SelectCommand, DeleteCommand, InsertCommand and UpdateCommand properties Contain the SELECT, DELETE, INSERT and UPDATE SQL statements, respectively – Parameters that are set programmatically are defined by Parameter elements – Parameters that obtain their values from controls are defined by ControlParameter elements

51  2008 Pearson Education, Inc. All rights reserved. 51 Fig. 25.30 | Guestbook application GUI in Design mode.

52  2008 Pearson Education, Inc. All rights reserved. 52 Fig. 25.31 | Configure Data Source dialog in Visual Web Developer.

53  2008 Pearson Education, Inc. All rights reserved. 53 Fig. 25.32 | Configuring the SELECT statement used by the SqlDataSource to retrieve data.

54  2008 Pearson Education, Inc. All rights reserved. 54 Fig. 25.33 | Previewing the data retrieved by the SqlDataSource.

55  2008 Pearson Education, Inc. All rights reserved. 55 Fig. 25.34 | Design mode displaying SqlDataSource control for a GridView.

56  2008 Pearson Education, Inc. All rights reserved. 56 Fig. 25.35 | Removing the MessageID column from the GridView.

57  2008 Pearson Education, Inc. All rights reserved. 57 Fig. 25.36 | Setting up INSERT parameters based on control values.

58  2008 Pearson Education, Inc. All rights reserved. 58 Outline Guestbook.aspx (1 of 6)

59  2008 Pearson Education, Inc. All rights reserved. 59 Outline Guestbook.aspx (2 of 6)

60  2008 Pearson Education, Inc. All rights reserved. 60 Outline Guestbook.aspx (3 of 6) Declare the GridView control Identifies the data source that is used to fill the GridView with data at runtime Properties that set various aspects of the GridView ’s appearance and behavior Define the columns that appear in the GridView Each BoundField represents a column

61  2008 Pearson Education, Inc. All rights reserved. 61 Outline Guestbook.aspx (4 of 6) Define a SqlDataSource control Indicates the connection through which the SqlDataSource control interacts which the database Indicates the control from which the parameter gets its value Specifies the property that contains the actual value to be used as the parameter value Parameters that obtain their values from controls Parameters that are set programmatically

62  2008 Pearson Education, Inc. All rights reserved. 62 Outline Guestbook.aspx (5 of 6)

63  2007 Pearson Education, Inc. All rights reserved. 63 25.5.2 Modifying the Code-Behind File for the Guestbook Application SqlDataSource – InsertParameters collection Contains an item corresponding to each parameter in the SqlDataSource ’s INSERT command – Insert method Executes the control’s INSERT command against the database GridView method DataBind – Refreshes the information displayed in the GridView

64  2008 Pearson Education, Inc. All rights reserved. 64 Outline Guestbook.aspx.vb (1 of 2) Assign a String representation of the current data to a new object of type Parameter Remove the Date item in the InsertParameters collection Add our Date parameter Executes the INSERT command against the database: add a row to the Messages table

65  2008 Pearson Education, Inc. All rights reserved. 65 Outline Guestbook.aspx.vb (2 of 2)

66  2008 Pearson Education, Inc. All rights reserved. 66 25.6.1 Examining the Completed Secure Books Database Application  Form authentication – Protect a page so that only users known to the site can access it  Example of visual inheritance: – Master page defines common GUI elements that are inherited by each page in a set of content pages

67  2007 Pearson Education, Inc. All rights reserved. 67 25.8.2 Creating the Secure Books Database Application Step 1: Creating the Web Site Step 2: Setting Up the Web Site’s Folders Step 3: Configuring the Application’s Security Settings (Fig. 25.46-50) – Access rule grants or denies access to a particular Web application directory for a specific user Step 4: Examining the Auto-Generated Web.config Files – authorization element indicates who is authorized to access a folder over the Web – mode attribute species that we want to use forms authentication – deny element specifies the users to whom we wish to deny access Step 5: Creating a Master Page (Fig. 25.51-53) – Master directive specifies that this file defines a master page – script element stores the code that is usually in the code behind file – ContentPlaceHolder control serves as a placeholder for content that will be defined

68  2007 Pearson Education, Inc. All rights reserved. 68 25.6.2 Creating the Secure Books Database Application (Cont.) Step 6: Creating a Content Page (Fig. 25.54-55) – Content control will place page-specific content that will replace the master page’s ContentPlaceHolder Step 7: Adding a CreateUserWizard Control to a Content Page (Fig. 25.56) Step 8: Creating a Login Page (Fig. 25.57) – ASP.NET writes an encrypted cookie containing data about an authenticated user – Authenticated user is redirected to the page specified by the Login control’s DestinationPageUrl property Step 9: Creating a Content Page That Only Authenticated Users Can Access Step 10: Customizing the Secure Page – LoginName control displays the current authenticated user name

69  2007 Pearson Education, Inc. All rights reserved. 69 25.6.2 Creating the Secure Books Database Application (Cont.) Step 11: Connecting the CreateUserWizard and Login Controls to the Secure Page Step 12: Generating a DataSet Based on the Books.mdf Database – ObjectDataSource encapsulates an object that provides access to a data source Step 13: Creating and Configuring an AuthorsTableAdapter (Fig. 25.58) Step 14: Creating and Configuring a TitlesTableAdapter (Fig. 25.59-60)

70  2007 Pearson Education, Inc. All rights reserved. 70 25.6.2 Creating the Secure Books Database Application (Cont.) Step 15: Adding a DropDownList Containing Authors’ First and Last Names (Fig. 25.61-63) – A business object is an object that accesses data through another object – DropDownList ’s AutoPostBack property indicates that a postback occurs each time the user selects an item Step 16: Creating a GridView to Display the Selected Author’s Books (Fig. 25.64-65) – Enable Sorting causes the column headings in the GridView to turn into hyperlinks that allow users to sort the data – Enable Paging causes the GridView to split across multiple pages – PageSize property determines the number of entries per page Step 17: Examining the Markup in Books.aspx (Fig. 25.66)

71  2008 Pearson Education, Inc. All rights reserved. 71 Fig. 25.46 | Web Site Administration Tool for configuring a web application.

72  2008 Pearson Education, Inc. All rights reserved. 72 Fig. 25.49 | Main page of the Web Site Administration Tool after enabling forms authentication.

73  2008 Pearson Education, Inc. All rights reserved. 73 Fig. 25.50 | Add New Access Rule page used to configure directory access.

74  2008 Pearson Education, Inc. All rights reserved. 74 Outline Bug2bug.master (1 of 2) Specify the language is VB Display logo picture

75  2008 Pearson Education, Inc. All rights reserved. 75 Outline Bug2bug.master (2 of 2) Define a ContentPlaceHolder control

76  2008 Pearson Education, Inc. All rights reserved. 76 Outline CreateNewUser.aspx (1 of 3) Specify language, master page, and title Replaces the master page’s ContentPlaceHolder Contains several properties that specify formatting styles for the control Elements that define additional styles used to format specific parts of the control Encapsulate the details of creating a user and issuing a confirmation message

77  2008 Pearson Education, Inc. All rights reserved. 77 Outline CreateNewUser.aspx (2 of 3)

78  2008 Pearson Education, Inc. All rights reserved. 78 Outline CreateNewUser.aspx (3 of 3)

79  2008 Pearson Education, Inc. All rights reserved. 79 Outline Login.aspx (1 of 2) Specify language, master page, and title Replaces the master page’s ContentPlaceHolder Create a Login control The elements define various formatting style applied to parts of the control

80  2008 Pearson Education, Inc. All rights reserved. 80 Outline Login.aspx (1 of 2)

81  2008 Pearson Education, Inc. All rights reserved. 81 Fig. 25.59 | Query Builder for designing a query that selects books written by a particular author.

82  2008 Pearson Education, Inc. All rights reserved. 82 Fig. 25.61 | Choosing a business object for an ObjectDataSource.

83  2008 Pearson Education, Inc. All rights reserved. 83 Fig. 25.62 | Choosing a data method of a business object for use with an ObjectDataSource.

84  2008 Pearson Education, Inc. All rights reserved. 84 Fig. 25.63 | Choosing a data source for a DropDownList.

85  2008 Pearson Education, Inc. All rights reserved. 85 Fig. 25.64 | Choosing the data source for a parameter in a business object’s data method.

86  2008 Pearson Education, Inc. All rights reserved. 86 Fig. 25.65 | Completed Books.aspx in Design mode.

87  2008 Pearson Education, Inc. All rights reserved. 87 Books.aspx (1 of 4) Outline Create a LoginName control; displays the authenticated user’s name when the page is requested and viewed in a browser Create a LoginStatus control; redirect user to login page after logging out Indicates that changing the selected item in the list causes a postback to occur Specifies that this ObjectDataSource accesses the Books database by calling GetData of BooksDataSet ’s AuthorsTableAdapter

88  2008 Pearson Education, Inc. All rights reserved. 88 Outline Books.aspx (2 of 4) Create the GridView that displays information about the books written by the selected author Define the ObjectDataSource used to fill the GridView with data Specifies that the value of method GetDataByAuthorID’s parameter comes from the SelectedValue property of authorsDropDownList

89  2008 Pearson Education, Inc. All rights reserved. 89 Outline Books.aspx (3 of 4)

90  2008 Pearson Education, Inc. All rights reserved. 90 Outline Books.aspx (4 of 4)

91  2008 Pearson Education, Inc. All rights reserved. 91 25.7 ASP.NET Ajax  Quickly and easily add Ajax functionality to existing ASP.NET web applications  www.asp.net/ajax/downloads www.asp.net/ajax/downloads  The Ajax Extensions package implements basic Ajax functionality  ASP.NET Ajax Control Toolkit contains rich, Ajax-enabled GUI controls

92  2008 Pearson Education, Inc. All rights reserved. 25.7 ASP.NET Ajax (cont.)  Add the ASP.NET Ajax Control Toolkit controls to the Toolbox in Visual Web Developer (or Visual Studio) – Right click the Toolbox and choose Add Tab – Type Ajax Toolkit in the new tab – Right click the tab and select Choose Items – Navigate to the folder in which you extracted the Ajax Control Toolkit and select AjaxControlToolkit.dll from the SampleWebSite\Bin folder – A list of available Ajax controls will appear under the Ajax Toolkit tab when you are in Design mode 92

93  2008 Pearson Education, Inc. All rights reserved. 25.7 ASP.NET Ajax (cont.)  Application was not initially set up to support Ajax functionality, so we must first modify the web.config file – Select File > New Website… to display the New Website dialog – Create an empty ASP.NET Ajax-Enabled Website – Open the web.config file in this new application and copy its contents – Open the Validation application and replace the contents of its web.config file with the contents of the web.config file you just copied – The new web.config file adds the system.web.extensions, httpHandlers and httpModules sections, which specify the settings for running scripts that enable Ajax functionality – To learn more about the details of these web.config modifications, visit www.asp.net/ajax/documentation/live/configuringASPNETAJAX.aspx 93

94  2008 Pearson Education, Inc. All rights reserved. 94 Outline Validation.aspx (1 of 5) Make Ajax toolkit available to the application Bundles the scripts for the toolkits controls

95  2008 Pearson Education, Inc. All rights reserved. 95 Outline Validation.aspx (2 of 5) Each of these displays error messages in yellow callouts next to the input field when necessary

96  2008 Pearson Education, Inc. All rights reserved. 96 Outline Validation.aspx (3 of 5)

97  2008 Pearson Education, Inc. All rights reserved. 97 Outline Validation.aspx (4 of 5) Eliminates full page refreshes by enabling partial page refreshes

98  2008 Pearson Education, Inc. All rights reserved. 98 Outline Validation.aspx (5 of 5)

99  2008 Pearson Education, Inc. All rights reserved. 99 Common Programming Error 25.1 Putting more than one instance of the ScriptManager control on a Web Form causes the application to throw an InvalidOperationException when the page is initialized.


Download ppt " 2008 Pearson Education, Inc. All rights reserved. 1 25 ASP.NET 2.0 and ASP.NET Ajax."

Similar presentations


Ads by Google