Web Development in ASP.NET Learner’s Guide Web Development in ASP.NET Learner’s Guide © 2013 Aptech Limited All rights reserved No part of this book may be reproduced or copied in any form or by any means – graphic, electronic or mechanical, including photocopying, recording, taping, or storing in information retrieval system or sent or transferred without the prior written permission of copyright owner Aptech Limited All trademarks acknowledged APTECH LIMITED Contact E-mail: ov-support@onlinevarsity.com Edition - 2013 Dear Learner, We congratulate you on your decision to pursue an Aptech Worldwide course Aptech Ltd designs its courses using a sound instructional design model – from conceptualization to execution, incorporating the following key aspects: Scanning the user system and needs assessment Needs assessment is carried out to find the educational and training needs of the learner Technology trends are regularly scanned and tracked by core teams at Aptech Ltd TAG* analyzes these on a monthly basis to understand the emerging technology training needs for the Industry An annual Industry Recruitment Profile Survey is conducted during August - October to understand the technologies that Industries would be adapting in the next to years An analysis of these trends & recruitment needs is then carried out to understand the skill requirements for different roles & career opportunities The skill requirements are then mapped with the learner profile (user system) to derive the Learning objectives for the different roles Needs analysis and design of curriculum The Learning objectives are then analyzed and translated into learning tasks Each learning task or activity is analyzed in terms of knowledge, skills and attitudes that are required to perform that task Teachers and domain experts this jointly These are then grouped in clusters to form the subjects to be covered by the curriculum In addition, the society, the teachers, and the industry expect certain knowledge and skills that are related to abilities such as learning-to-learn, thinking, adaptability, problem solving, positive attitude etc These competencies would cover both cognitive and affective domains A precedence diagram for the subjects is drawn where the prerequisites for each subject are graphically illustrated The number of levels in this diagram is determined by the duration of the course in terms of number of semesters etc Using the precedence diagram and the time duration for each subject, the curriculum is organized Design & development of instructional materials The content outlines are developed by including additional topics that are required for the completion of the domain and for the logical development of the competencies identified Evaluation strategy and scheme is developed for the subject The topics are arranged/organized in a meaningful sequence The detailed instructional material – Training aids, Learner material, reference material, project guidelines, etc.- are then developed Rigorous quality checks are conducted at every stage Strategies for delivery of instruction Careful consideration is given for the integral development of abilities like thinking, problem solving, learning-to-learn etc by selecting appropriate instructional strategies (training methodology), instructional activities and instructional materials The area of IT is fast changing and nebulous Hence considerable flexibility is provided in the instructional process by specially including creative activities with group interaction between the students and the trainer The positive aspects of Web based learning –acquiring information, organizing information and acting on the basis of insufficient information are some of the aspects, which are incorporated, in the instructional process Assessment of learning The learning is assessed through different modes – tests, assignments & projects The assessment system is designed to evaluate the level of knowledge & skills as defined by the learning objectives Evaluation of instructional process and instructional materials The instructional process is backed by an elaborate monitoring system to evaluate - on-time delivery, understanding of a subject module, ability of the instructor to impart learning As an integral part of this process, we request you to kindly send us your feedback in the reply prepaid form appended at the end of each module *TAG – Technology & Academics Group comprises of members from Aptech Ltd., professors from reputed Academic Institutions, Senior Managers from Industry, Technical gurus from Software Majors & representatives from regulatory organizations/forums Technology heads of Aptech Ltd meet on a monthly basis to share and evaluate the technology trends The group interfaces with the representatives of the TAG thrice a year to review and validate the technology and academic directions and endeavors of Aptech Ltd Aptech New Products Design Model Key Aspects Scanning the user system and needs assessment Evaluation of Instructional Processes and Material Need Analysis and design of curriculum Design and development of instructional material Assessment of learning Strategies for delivery of instructions “ “ A little learning is a dangerous thing, but a lot of ignorance is just as bad Preface Over the last few decades, the Internet and the world of Web applications have seen a lot of changes Earlier, Web applications could offer only static content with hardly any dynamic elements Visitors used to just read the information User interaction was very minimal Today however, Web applications are extremely dynamic reflecting the changing times and technologies Microsoft has yet again conquered developer's hearts by offering ASP.NET for the Web application world ASP.NET allows Web programmers to create efficient, dynamic Web applications which can seamlessly interoperate with database and Web servers As ASP.NET has been built for the NET platform, it can take full advantage of the features offered by the NET framework Another advantage of ASP.NET is that it supports NET languages such as C# and VB.NET This book uses C# for coding the ASP Web pages This book helps beginners in ASP.NET to learn to develop a Web application using ASP.NET and at the same time covers various powerful features of ASP.NET enabling them to build complex Web applications This book covers an introduction to Web Forms, new features of Web development environment, ASP NET page model, basic event handling, intrinsic objects in Web applications such as Response, Request, Application and Server Various categories of Web server controls such as basic Web server controls, selection and validation Web server controls are discussed in depth The book also covers mobile application development with ASP.NET and explores how to trace and debug Web applications In ASP NET 3.5, Microsoft has added several new features and enhanced existing features enabling developers to build ���������������������������������������������������������������������������������������������� powerful, robust, rich, and secure Web applications ����������������������������������������� The book includes an overview of the new features introduced in ASP.NET 3.5 and Visual Studio 2008 Integrated Development Environment (IDE), and explores various other features such as nested master pages and so forth The book describes the use of stored ������������������������������������������ procedures and Language Integrated Query ��������������������������������������������������� (LINQ) with ASP.NET 3.5 to achieve efficient and secure data manipulation The book concludes with a description of eXtensible Markup Language (XML) Web services and ASP.NET Asynchronous JavaScript and XML (AJAX) This book is the result of a concentrated effort of the Design Team, which is continuously striving to bring you the best and the latest in Information Technology The process of design has been a part of the ISO 9001 certification for Aptech-IT Division, Education Support Services As part of Aptech’s quality drive, this team does intensive research and curriculum enrichment to keep it in line with industry trends We will be glad to receive your suggestions Design Team “ Knowing is not enough we must apply; Willing is not enough, we must “ Table of Contents Modules Introduction to ASP.NET Working with the IDE .16 Basics of ASP.NET 29 Request, Response, and Server Objects 48 Basic Web Server Controls .76 More Web Server Controls 96 Advanced Web Controls 127 HTML Server Controls 166 Validation Controls 193 10 Application, Session, and Cookies 221 11 An Introduction to Mobile Applications 245 12 Tracing, Debugging, and Diagnostics 265 13 Introduction to ASP.NET 3.5 298 14 Introduction to ASP.NET 3.5 (Lab) 321 15 Working with ASP.NET 3.5 344 16 Working with ASP.NET 3.5 (Lab) 362 17 Authentication and Authorization 18 Authentication and Authorization (Lab) 403 19 Master Pages and Web Parts 423 20 Master Pages and Web Parts (Lab) 451 21 Working with Stored Procedures and LINQ 470 384 Table of Contents Modules 22 Working with Stored Procedures and LINQ (Lab) 492 23 ASP.NET AJAX and XML Web Services 519 24 ASP.NET AJAX and XML Web Services (Lab) 554 24 Module ASP.NET AJAX and XML Web Services (Lab) 10 Add an HTML table to the form 11 Add three Label and two DropDownList controls to the form Also, add an Image and Button control 12 Configure their properties as shown in table 24.4 Server Control Label DropDownList Image Label DropDownList Button Label Property ID Text ID Items ID ImageUrl ID Text ID Items ID Text ID Text Value lblType Enter the Coffee Type: ddlType Espresso Cappuccino Turkish Arabian imgCoffee ~/Images/coffee.jpg lblSize Enter Size: ddlSize Small Medium Large btnDone Done lblPrice Concepts Table 24.4: Properties of Controls on MenuPage Web Form V 1.0 © Aptech Limited 575 of 582 Module 13 24 ASP.NET AJAX and XML Web Services (Lab) Arrange the controls as shown in figure 24.16 Figure 24.16: User Interface of MenuPage Web Form 14 Declare two variables in MenuPage.aspx.cs as follows: // Declare variables string type, size; These variables will be used to store the type and size of the coffee chosen by the user 15 Add the code to Page _ Load event handler in MenuPage.aspx.cs as follows: /// /// Sets the type and size values /// Concepts /// /// protected void Page_Load(object sender, EventArgs e) { 576 of 582 V 1.0 © Aptech Limited Module 24 ASP.NET AJAX and XML Web Services (Lab) if (!IsPostBack) { type = ddlType.Items[0].Text.ToString(); size = ddlSize.Items[0].Text; } else { // Set the defaults so that if the user does not select // any option, the default value would be read type = ddlType.SelectedItem.Text.ToString(); size = ddlSize.SelectedItem.Text.ToString(); } } The code creates two variables type and size, and assigns the value of type and size respectively chosen by the user If the user has not chosen any value, the default value in the drop-down controls is taken To consume the Web service created earlier, you first need to add a reference to the Web service namespace Right-click the project name, OmegaCoffee, in Solution Explorer Select Add Web Reference from the context menu Concepts V 1.0 © Aptech Limited 577 of 582 Module 24 ASP.NET AJAX and XML Web Services (Lab) This displays the Add Web Reference dialog box as shown in figure 24.17 Figure 24.17: Add Web Reference Dialog Box Click ‘Web services in this solution’ CoffeePriceService is displayed in the Add Web Reference dialog box Concepts 578 of 582 V 1.0 © Aptech Limited Module 24 ASP.NET AJAX and XML Web Services (Lab) Type the service reference name as OmegaServiceReference as shown in figure 24.18 Figure 24.18: Adding Web Reference Click Add Reference to add the service reference Concepts V 1.0 © Aptech Limited 579 of 582 Module 24 ASP.NET AJAX and XML Web Services (Lab) Figure 24.19 shows the files that are automatically created as a result of adding the service reference The disco file is the discovery file and the wsdl file is the WSDL document for the Web service Figure 24.19: Service Reference and the Autogenerated Files Generate Click event for the button, Done, and add the following code to the event handler: /// /// Retrieves the price of coffee based on size and type using Web /// service instance /// /// Concepts /// protected void btnDone_Click(object sender, EventArgs e) { 580 of 582 V 1.0 © Aptech Limited Module 24 ASP.NET AJAX and XML Web Services (Lab) CoffeePriceService objCoffeePrice = new CoffeePriceService(); lblPrice.Text = “The Price of the Coffee is: $”; lblPrice.Text += objCoffeePrice.GetPrice(type,size).ToString (); } This code creates a new instance of the Web service, CoffeePriceService, and calls the GetPrice() Web method with the parameters type and size The result of the method call is converted to string format and assigned to the Text property of the label, lblPrice Save, build, and execute the application Concepts The output depicted in figure 24.20 shows the coffee type as Turkish and size as Medium and the resulting price for this set Figure 24.20: Displaying Price Based on Type and Size Selected V 1.0 © Aptech Limited 581 of 582 Module 24 ASP.NET AJAX and XML Web Services (Lab) 24.2 Part II - 30 Minutes Modify the DataSurvey Web application shown in Part I and add a Timer control from AJAX Extensions tab in the Toolbox The Web Form should have an additional Label displaying the current time including seconds The time value in the Label should refresh every second Hints: Add a Timer control inside the UpdatePanel Set the Interval property to 1000 Handle its Tick event to update the latest time in the Label control Create a Web application having a simple login Web Form It should make use of AJAX Toolkit controls such as AutoCompleteExtender and ConfirmButtonExtender Hints: Using the smart tag with the TextBox control, you can add the extenders Configure their properties 24.3 Do It Yourself Concepts Harris Associates is a legal firm in Chicago city They often undertake prosecution of high profile criminal cases The firm has recently expanded their operations overseas with local representatives in each region They have a centralized online billing system This system has a unique condition - currency values must be provided in United States (US) dollars only Hence, they have approached you to seek your expertise as a Web application developer You must create a Web service-based application for a global currency converter 582 of 582 V 1.0 © Aptech Limited A Answers Answers to Knowledge Checks Module Knowledge Check 1 C A D A Answers Knowledge Check Knowledge Check D C Module Knowledge Check 1 C D Knowledge Check D Knowledge Check C Module Knowledge Check 1 C D V 1.0 © Aptech Limited Answers to Knowledge Checks Answers to Knowledge Checks Knowledge Check A B B Answers Knowledge Check C D Module Knowledge Check 1 C B Knowledge Check D A Knowledge Check B A Module Knowledge Check 1 C B Knowledge Check A A B V 1.0 © Aptech Limited ii Answers to Knowledge Checks Answers to Knowledge Checks Module Knowledge Check 1 C B Knowledge Check B B Answers Module Knowledge Check 1 D B Knowledge Check B A Knowledge Check A D Module Knowledge Check 1 B B Knowledge Check B D V 1.0 © Aptech Limited iii Answers to Knowledge Checks Answers to Knowledge Checks Knowledge Check B Module Knowledge Check 1 C D Answers Knowledge Check C A Module 10 Knowledge Check 1 A A Knowledge Check C C Knowledge Check A Knowledge Check D Module 11 Knowledge Check 1 D Knowledge Check D V 1.0 © Aptech Limited iv Answers to Knowledge Checks Answers to Knowledge Checks Knowledge Check D B Module 12 Knowledge Check 1 A Knowledge Check A Answers Knowledge Check A A Module 13 Knowledge Check 1 C A, D A, B, D B, C, D B, C, D D A Module 15 Knowledge Check 1 A, C C, D B, C, D V 1.0 © Aptech Limited Answers to Knowledge Checks Answers to Knowledge Checks A, D A, B A, B Module 17 Answers Knowledge Check 1 A, C, E A, C, D C A A-5, B-4, C-1, D-2, E-3 Module 19 Knowledge Check 1 C, E A-3, B-5, C-1, D-4, E-2 A, C, E A, D, E A-2, B-1, C-4, D-3 A, B, D C Module 21 Knowledge Check 1 A A B A, B, C V 1.0 © Aptech Limited vi Answers to Knowledge Checks Answers to Knowledge Checks A B Module 23 A, B, C A B A B B Answers Knowledge Check V 1.0 © Aptech Limited vii ... about: ASP and ASP. NET Web Forms ASP. NET Application Development Module Introduction to ASP. NET 1.1 ASP and ASP. NET In this first lesson, ASP and ASP. NET, you will learn to: Outline the... Descriptions Helps in coding in any NET Framework language Helps in maintaining the state between the Web Forms Helps in adding extra components to the Web Form Helps in rendering the Web Form on any... through the Web) ASP. NET plays a vital role in developing Web applications with NET; without using ASP. NET, this would not be possible ASP. NET supports server-side code written in any NET compatible