11 User Controls II Chapter 11. 2 Objectives You will be able to Create a realistic reusable user control. Use data binding in a user control. Change.

Slides:



Advertisements
Similar presentations
ASP.NET Ajax Supplementary Tutorial. Why Use ASP.NET AJAX? - I ASP.NET AJAX enables you to build rich Web applications that have many advantages over.
Advertisements

1 Northwind Traders Order Entry. 2 Northwind Traders Call Center Add an Order Entry capability to the Northwind Traders Call Center application. Start.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
11 ASP.NET Controls II Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.
Using ADO.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
Figure 1. Hit analysis in 2002 of database-driven web applications Hits by Category in 2002 N = 73,873 Results Reporting 27% GME 26% Research 20% Bed Availability.
11 ASP.NET Controls Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
ASP.Net, Web Forms and Web Controls 1 Outline Introduction Simple HTTP Transaction System Architecture Creating and Running a Simple Web Form Example Web.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
1 Working with MS SQL Server. 2 Objectives You will be able to Use Visual Studio for GUI based interactive access to a Microsoft SQL Server database.
JavaScript & jQuery the missing manual Chapter 11
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
ASP.NET Part 4 Instructor: Charles Moen CSCI/CINF 4230.
Beginning Web Site Development Module 1 – Dynamic Web Site Development Fundamentals of building dynamic Web sites with ASP.NET 2.0 and C# Version.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Chapter 71 Building Data-Driven ASP.NET Applications Introduction to ASP.NET By Kathleen Kalata.
11 Updating a Database Table Textbook Chapter 14.
Navigating database with windows forms.. Tiered applications  Provide a means to develop many presentations of the same app  Makes changes to the back.
1 Project 4: XML Product Browser (Not Graded). Objectives This project is an exercise of the following knowledge and skills: Accessing and displaying.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
1 Databound Controls. 2 Objectives You will be able to use design time data binding to display and update SQL Server database data without writing any.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
1 Working with MS SQL Server Textbook Chapter 14.
Internet Technologies and Web Application Web Services With ASP.NET Tutorial: Introduction to.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
11 Using ADO.NET II Textbook Chapter Getting Started Last class we started a simple example of using ADO.NET operations to access the Addresses.
Caching Chapter 12. Caching For high-performance apps Caching: storing frequently-used items in memory –Accessed more quickly Cached Web Form bypasses:
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
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.
ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn.
1 Project 3: Chomp (Not graded). 2 Project 3 The game of Chomp was described in a Math Trek column in Science News:
Dynamic Dropdown Lists 1. Objectives You will be able to Use Dropdown Lists to solicit multiple choice user input in an ASPX web page. Populate a Dropdown.
1 Project 7: Northwind Traders Order Entry. 2 Northwind Order Entry Extend the Select Customer program from Project 6 to permit the user to enter orders.
Chapter 8 Working With Databases in ASP.NET. Listing 8.1 – ShowListControls Uses The SqlDataSource control for estabishing database connectivity and.
ASP.NET More on searching databases 1ASP.NET, More on searching databases.
1 More About HTML Tables and Images. 22 Objectives You will be able to Create tables in HTML. Include images in your HTML page. Create links to other.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
TRAINING SESSIONS.NET Controls.  Standard Controls  Label  Textbox  Checkbox  Button, Image Button, Image control  Radio Button  Literal  Hyperlink.
11 The Repeater Control. 22 Objectives You will be able to use a Repeater Control to display data obtained with a SQL query with custom formatting.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 12 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 12 Accessing.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
1 HTML Tables. 22 Objectives You will be able to Create tables in HTML.
11 ASP.NET Server Controls Beginning ASP.NET in C# and VB Chapter 4.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
11 Getting Started with ASP.NET Beginning ASP.NET in C# and VB Chapters 1 and 2.
1111 Creating HTML Programatically Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML.
1 Project 4 Address Lookup. Project 4 Write an ASP.NET app that permits users to retrieve addresses from a potentially large list of addresses. There.
Unit 8.2 Learning Objectives Data Warehouses – The Role of Data Warehouses The Role of Data Warehouses – Group Exercise Accessing Data in Views – Accessing.
1111 Master Pages Beginning ASP.NET in C# and VB Chapter 6.
Module 10: Data Access in ASP.NET. Overview Overview of the ASP.NET Data Access What is Data Access List of Data Source Control What is Data Bound How.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
Creating a Web Site Creating a new Web site Defining and using folders Creating and editing Web pages Viewing pages in a Web browser.
Beginning ASP.NET in C# and VB Chapter 9
1 Project 5 Eyeglass Rx User Control. Eyeglass Rx Earlier in the semester we looked at an eyeglass prescription as an example of an HTML table. 2.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Listing 9.1 ShowLocalConnection.aspx
Using List Controls with SQL Server
ASP.NET.
Chapter 10 Accessing Database Files
Presentation transcript:

11 User Controls II Chapter 11

2 Objectives You will be able to Create a realistic reusable user control. Use data binding in a user control. Change the page content displayed by a user control from the code-behind file of the page that contains the user control.

33 A Real User Control Reusable Eyeglass Prescription Display User control shows Rx as a table. Needed in several places in a real web app. This is a minor simplification of the real one. User control gets Rx data from a SQL Server database. Uses Data Binding with SqlDataSource. SELECT command has parameter for Rx ID.

4 Reality Check This is just an example. Demonstrating the use of data binding in a nontrivial user control. A real user control like this would probably use low level ADO classes and methods. There is a high performance cost for data binding multiple controls as done in this example.

55 Eyeglass Rx User Control

66 The Database Tables Tables Rx Used by the user control. Patients Will not be used this semester. Download SQL scripts to build your own copies of these tables: Downloads/Eyeglass_Rx_User_Control/ Downloads/Eyeglass_Rx_User_Control/ File create_prescriptions.sql

77 Creating Table Rx

88 Table Rx Definition

99 Table Rx Contents

10 Demo Web Site Container page has a databound dropdown list for Rx IDs. All Rx IDs in table Rx User control displays a single Rx HTML table cells data bound to SQL Data Source Query for table Rx specifies Rx ID in WHERE clause. When user selects an ID from the dropdown list, app displays that Rx in the user control. Client code sets a property of the user control to specify Rx ID. User control updates its SELECT command. Rebinds to fill HTML table with values from the specified Rx in the database table.

11 Demo Web Site Create a new ASPX web site for demo of the Eyeglass Rx user control. Rx_Demo Add a SqlDataSource This one for Rx IDs to populate the dropdown list. Put it below the form in Default.aspx

12 The SqlDataSource

13 In Design View

14 Configure the SQL Data Source

15 Configure the SQL Data Source

16 Configure the SQL Data Source

17 Configure the SQL Data Source

18 Configure the SQL Data Source

19 Add a DropDownList Inside the div ID: ddlRxID DataSourceID: SqlDataSource1 DataTextField: RxID DataValueField: RxID Enable AutoPostback AppendDataBoundItems = true Add dummy initial item Select Rx

20 Configure the DropDownList

21 The DropDownList

22 Initial Dummy Item

23 Add Label Add a label beside the dropdown list. Used for messages to the user Double click on the dropdown list Visual Studio adds an event handler

24 Rx ID Selected Event Handler Start with a stub: protected void ddlRxID_SelectedIndexChanged(object sender, EventArgs e) { lblMessage.Text = "Rx ID " + ddlRxID.SelectedValue + " selected"; } Try it!

25 Default.aspx

26 Selecting Rx 10

27 After Rx 10 Selected

28 User Control Eyeglass_Rx User control Eyeglass_Rx will display one eyeglass prescription Values from database table Rx. Identified by RxID Website > Add new item. Web User Control Name: Eyeglass_Rx.ascx Language: Visual C#

29 User Control Eyeglass_Rx

30 Eyeglass_Rx.ascx Initial File Source View Control Language="C#" AutoEventWireup="true" CodeFile="Eyeglass_Rx.ascx.cs" Inherits="Eyeglass_Rx" %> Note Control vs Page Add an HTML Table

31 Control Language="C#" AutoEventWireup="true" CodeFile="Eyeglass_Rx.ascx.cs" Inherits="Eyeglass_Rx" %>. Sphere Cyl Axis Prism Base Add Seg PD NPD 31 Eyeglass_Rx.ascx

32 Eyeglass_Rx.ascx OD

33 Eyeglass_Rx.ascx OS

34 User Control Eyeglass_Rx Design View

35 Building the User Control Add a SqlDataSource. Below the table. Configure it for your scorpius database. Set the SELECT command. SELECT * FROM Rx WHERE

36 Configure SqlDataSource We can use the same connection that we created for the.aspx page.

37 Configure SqlDataSource Click WHERE

38 Configure SqlDataSource Click Add

39 Configure SqlDataSource Click OK

40 Configure SqlDataSource Click Next

41 Configure SqlDataSource Click Test Query then fill in Value

42 Query Test Click OK Value is parameter value for the Query Test

43 Query Test Result Click Finish

44 Building the User Control Add a Repeater Above the table Add an ItemTemplate inside the Repeater. We are using the Repeater just to provide a container that we can bind to a SqlDataSource. There will always be exactly one Rx. We select on the RxID, which is the Primary Key. Guaranteed to be unique.

45 Repeater

46 Make the ItemTemplate enclose the table

47 Configure the Repeater

48 Add Data Bindings for Second Row OD

49 Add Data Bindings for Third Row OS

50 Style the Table <table style="border:solid 1px; background-color:LightYellow; padding:2; border-collapse: collapse">

51 Setting the Rx ID The SqlDataSource in the user control has a command parameter for the RxID Need to be able to set it from our C# code in the page-behind file for the container page. ddlRxID SelectedIndexChanged Event Handler Define a property in Eyeglass_Rx.ascx Settable from the outside world. Update the command parameter and rebind the table to the data source whenever the Rx ID property is set.

52 Eyeglass_Rx.ascx.cs using System; using System.Configuration; using System.Data; using System.Web; using System.Web.UI.WebControls; public partial class Eyeglass_Rx : System.Web.UI.UserControl { private int rxid; public int Rxid { set { rxid = value; Rebind(); } } private void Rebind() { // Update the command parameter of the SELECT command SqlDataSource1.SelectParameters[0].DefaultValue = rxid.ToString(); Repeater1.DataBind(); } Setting the Rxid property refills the table data.

53 Setting the User Control's Rxid Property protected void ddlRxID_SelectedIndexChanged( object sender, EventArgs e) { Eyeglass_Rx1.Rxid = int.Parse(ddlRxID.SelectedItem.Value); } Default.aspx.cs Replace the stub with the real event handler.

54 Add the User Control to Default.aspx

55 User Control Eyeglass_Rx.ascx In Use End of Presentation