murach's asp.net 4 web programming with c 2010 · chapter7 howto usethevalidation controls...

12
TRAINING & REFERENCE murach's web programming with C# 2010 Anne Boehm Joel Murach Va. Mike Murach & Associates, Inc. I J) 1-800-221-5528 (559) 440-9071 Fax: (559) 44(M)963 [email protected] www.murach.com

Upload: others

Post on 15-Oct-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

TRAINING & REFERENCE

murach's

web programming with

C# 2010

Anne Boehm Joel Murach

Va. Mike Murach & Associates, Inc.IJ) 1-800-221-5528 • (559) 440-9071 • Fax: (559) 44(M)963

[email protected] • www.murach.com

Page 2: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

Expanded contents

Section 1 The essence off ASP.NET web programming

Chapter 1 An introduction to ASP.NET web programmingAn introduction to web applications 4

Two pages of a Shopping Cart application 4

The hardware and software components for web applications 6

How static web pages work 8

How dynamic web pages work 10

How state is handled in ASP.NET applications 12

An introduction to ASP.NET application development 14

The software you need 14

The components of the .NET Framework 16

Three environments for developing ASP.NET applications 18

A quick preview of how an ASP.NET application works 20

The files used by the Shopping Cart application 20

The aspx code for the Order form 22

The C# code for the Order form 24

How an ASP.NET application is compiled and run 26

Chapter 2 How to develop a one-page web applicationHow to work with ASP.NET web sites 32

How to start a new web site 32

How to add a web form to a web site 34

How to work with the Visual Studio IDE 36

How to add folders and files to a web site 38

How to open or close an existing web site 40

How to use Design view to build a web form 42

The design of the Future Value form 42

How to use flow layout 44

How to add a table to a form 46

How to add text to the cells of a table 46

How to add server controls to a form 48

How to set the properties of the controls 48

Common properties for web server controls 50

How to work in Source and Split views 52

How to use Source view to modify the design 52

How to use Split view to work with the design 54

How to use code snippets 56

The aspx code for the Future Value form 58

How to add validation controls to a form 60

An introduction to the validation controls 60

How to use the required field validator 62

How to use the range validator 62

How to add code to a form 64

How to use the Code Editor 64

How to use page and control events 66

The C# code for the Future Value form 68

Page 3: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

Expanded contents

How to test a web application 70

How to run a web site with the built-in development server 70

How to review the HTML that's sent to the browser 72

Chapter 3 How to develop a multi-page web applicationThe Shopping Cart application 78

The Order page • 78

The Cart page 80

The files and folders used by the Shopping Cart application 82

How to add a class to a web site 84

Six skills for working with multiple web forms 86

How to create a web site with starting files and folders 86

How to rename a web form 88

How to change the starting web form 88

How to redirect or transfer to another page 90

How to use cross-page posting 92

How to code absolute and relative URLs 94

How to create and use data sources 96

How to create an Access data source 96

How to configure an Access data source 98

How to bind a drop-down list to a data source 100

How to use C# code to get data from a data source 102

How to use session state 104

How session state works 104

How to work with data in session state 106

The code for the Shopping Cart application 108

The code for the Product class 108

The code for the Cartltem class 108

The code for the CartltemList class 110

The aspx code for the Order page 112

The C# code for the Order page 116

The aspx code for the Cart page 118

The C# code for the Cart page 120

Chapter 4 How to test and debug an ASP.NET applicationHow to test an application using the ASP.NET Development Server.... 128

How to test an application with the default browser 128

How to test an application with a browser other than the default 130

How to use the Exception Assistant 132

How to test an application using IIS 134

How to create a local IIS web site 134

How to test a file-system web site with IIS 136

How to test an application from outside ofVisual Studio 138

How to use the debugger 140

How to use breakpoints 140

How to use tracepoints 142

How to work in break mode 144

How to control the execution of an application 146

How to use the Autos, Locals, and Watch windows to monitor variables 148

How to use the Immediate window to work with values 150

Page 4: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

Expanded contents

How to use theTrace feature 152

How to enable the Trace feature 152

How to interpret Trace output 152

How to create custom trace messages 154

How to write information directly to the HTTP output stream 156

Chapter 5 A crash couse in HTML and CSS

An introduction to HTML 162

Basic rules for coding HTML elements 162

How to work with HTML using Visual Studio 164

How web server controls are rendered 166

How to code HTML documents 168

The basic structure of an HTML document 168

The Page directive 170

The Doctype declaration 170

How to code block elements 172

How to code inline elements 174

Basic skills for using CSS 176

How to include CSS in a web page 176

How to code CSS rule sets and comments 178

How to code selectors for elements, IDs, and classes 180

A Future Value page that uses CSS 182

The aspx code for the Future Value form 184

The CSS for the Future Value form 186

Visual Studio features for working with CSS 190

How to work with styles from Design view 190

How to add style rules 192

How to create and edit external style sheets 194

How to use the Apply Styles window 196

How to use the CSS Properties window 198

How to use the Manage Styles window 200

Section 2 Basic ASP.NET skills

Chapter 6 How to work with server controls

An introduction to server controls 208

Types of server controls 208

The web server controls presented in this chapter 210

How to handle control events 212

How to use access keys with web server controls 214

How to set the focus on a web server control 214

How to set the default button control 214

How to work with button controls 216

How to work with buttons, link buttons, and image buttons 216

How to use the e argument of an image button control 218

How to use the Command event 220

How to work with text boxes, labels, check boxes,and radio buttons 222

How to work with text boxes and labels 222

How to work with check boxes and radio buttons 224

C# code for working with these controls 226

Page 5: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

Expanded contents ix

How to work with list controls 228

Basic skills for working with list boxes and drop-down lists 228

Properties for working with list boxes, drop-down lists, and list items 230

Properties and methods for working with list item collections 232

How to use the Listltem Collection Editor 234

How to work with radio button lists and check box lists 236

How to work with bulleted lists and numbered lists 238

How to use other web server controls 240

How to get the information you need for using a control 240

How to use the image control 242

How to use the hyperlink control 242

How to use the file upload control 244

How to use the image map control 246

How to use the calendar control 248

Chapter 7 How to use the validation controls

An introduction to the validation controls 254

How to use the validation controls 254

Common validator properties 256

How ASP.NET processes validation controls 258

How to use the basic validation controls 260

How to use the required field validator 260

How to use the compare validator 262

How to use the range validator,

264

Validation techniques 266

How to use the validation summary control 266

How to use validation groups 268

How to use the advanced validation controls 270

How to use the regular expression validator 270

How to create your own regular expressions 272

How to use a custom validator 274

A validation routine that validates credit card numbers 276

Chapter 8 How to manage state

How to use view state 282

How to work with view state 282

How to use view state for your own data 284

How to use session state 286

How to work with session state 286

When to save and retrieve session state items 288

Options for storing session state data 290

Options for tracking session IDs 290

How to set session state options 292

How to use application state 294

How application state works 294

How to work with application state data 296

How to work with application events 298

How to use cookies and URL encoding 300

How to create cookies 300

How to work with cookies 302

How to enable or disable cookies 304

How to use URL encoding 306

Page 6: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

X Expanded contents

Chapter 9 How to use master pages

How to create master pages 312

An introduction to master pages 312

How to create a master page 314

The aspx code for a new master page 316

The aspx code for the Halloween Store master page 318

The code-behind file for the master page 320

How to create and develop content pages 322

How to create a content page 322

How to add content to a page 324

The aspx code for the Order content page 326

How to nest master pages 328

How to create nested master pages 328

How to add content to a child master page 328

How to access master page controls from a content page 330

How to expose a master page control as a public property 330

How to access a public property of the master page from a content page 332

Chapter 10 How to use site navigationAn introduction to site navigation 338

An introduction to the navigation controls 338

How to create a web.sitemap file 340

The web.sitemap file for the Navigation application 342

How to use the site navigation controls 344

How to use the TreeView control 344

How to create a SiteMapDataSource control 346

How to use the Menu control 348

How to use the SiteMapPath control 350

A master page for the Navigation application 352

Chapter 11 How to use themes

An introduction to themes 358

A page before and after a theme has been applied 358

How themes work—•

360

How to create themes 360

How to work with skins 362

How to create and use skins 362

Another way to store skins 364

How to use customization themes 366

How to apply a customization theme to an application 366

How to apply a customization theme to a page 366

How to apply a skin to a control 366

How to remove a customization theme from an application 368

How to remove a customization theme from a page 368

How to remove a customization theme from a control 368

How to use style sheet themes 370

How to apply a style sheet theme 370

How to remove a style sheet theme 370

Page 7: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

Expanded contents Xi

Section 3 ASP.NET database programming

Chapter 12 An introduction to database programmingAn introduction to relational databases 378How a table is organized 378

How the tables in a database are related 380

How the columns in a table are defined 382

The design of the Halloween database 384

How to use SQL to work with the data in a relational database 386

How to query a single table 386

How to join data from two or more tables .-. 388

How to add, update, and delete data in a table 390

An introduction to ADO.NET 4 392

How the basic ADO.NET components work 392

Concurrency and the disconnected data architecture 394

How to work with data without using a data adapter 396

An introduction to the ADO.NET 4 classes 398The SqlConnection class 398The SqlCommand class 398

The SqlParameter class 400

The SqlDataReader class 400

The SqlDataAdapter class 400

Chapter 13 How to use SQL data sources

How to create a SQL data source 404

A Product List application that uses two SQL data sources 404

How to create a SqlDataSource control 406

How to define the connection '. 408

How to save the connection string in the web.config file 410

How to configure the Select statement 412

How to create a Where clause 414

How select parameters work 416

How to use custom statements and stored procedures 418

How to enter custom statements 418

How to select stored procedures 418

How to create a Select statement with the Query Builder 420

How to define the parameters 422

How to use the DataList control 424

How the DataList control works 424

How to define the templates for a data list 426

How to format a data list 428

How to use data binding 430

How to bind a list control to a data source 430How to bind the controls in a template 432

The aspx file for the Product List application 434

How to use the advanced features of a SQL data source 436

How to create a data source that can update the database 436

How to change the data source mode 438How to use caching 438

Page 8: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

Expanded contents

Chapter 14 How to use the GridView control

How to customize the GridView control

How the GridView control works

How to define the fields in a GridView control

Elements used to create and format fields

How to enable sortingHow to enable paging

How to customize paging

A list application that uses a GridView control

The Product List applicationThe aspx file

.....

How to update GridView data

How to work with command fields

How to use events raised by the GridView control

How to insert a row in a GridView control

A maintenance application that uses a GridView control

The Category Maintenance applicationThe aspx file

The code-behind file

How to work with template fields

How to create template fields

The template version of the Category Maintenance applicationThe aspx code for the template version

Chapter 15 How to use the DetailsView and FormView controls

How to use the DetailsView control 484

An introduction to the DetailsView control

Attributes and child elements for the DetailsView control

How to define the fields in a DetailsView control

How to enable pagingHow to create a Master/Detail page

How to update DetailsView data

An introduction to command buttons

How to add command buttons

How to use events raised by the DetailsView control

How to create template fields

The Product Maintenance applicationThe operation of the applicationThe aspx file

The code-behind file

How to use the FormView control

An introduction to the FormView control

How to work with the Item templateHow to work with the Editltem and Insertltem templates

A Shopping Cart application that uses a FormView control

The operation of the applicationThe aspx file for the Order page

The code-behind file for the Order page

Page 9: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

Expanded contents XMi

Chapter 16 How to use the ListView and DataPager controls

How to use the ListView control 524

An introduction to the ListView control 524

How to configure a ListView control 526

How to work with the Layout template 528

How to work with the Item template 530

How to provide for sorting 532

How to provide for paging 534

How to customize paging 536

A list application that uses a ListView control 538

The Product List application 538

The aspx file 540

How to group ListView data 544

How to define the templates for a group 544

A Product List application that uses groups 546

The aspx file for the grouped Product List application 546

How to update ListView data 550

How to use buttons to perform update operations 550

How to work with the Editltem and Insertltem templates 552

How to use events raised by the ListView control 552

A maintenance application that uses a ListView control 554

The Category Maintenance application 554

The aspx file 556

The code-behind file 556

Chapter 17 How to use object data sources

An introduction to object data sources .. 566

How 3-layer applications work in ASP.NET 566

How to use the ObjectDataSource control 568

How to configure an ObjectDataSource control 570

How to work with bound controls 570

A Product List application 572

The aspx file 574

The ProductDB class 576

How to create a data access class 578

How to design a data access class 578

How to create a select method 580

How to create update, delete, and insert methods 582

How to use attributes to mark a data access class 584

A Category Maintenance application 586

The design 586

The aspx file 586

The code-behind file 590

The Category class 592

The CategoryDB class 594

How to use paging with object data sources 598

How to create an ObjectDataSource control that provides for paging 598

How to create a data access class that provides for paging 600

Page 10: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

Expanded contents

Section 4 Professional ASP.NET skills

Chapter 18 How to secure a web site

An introduction to SSL 608

How secure connections work 608

How digital secure certificates work 610

How to determine if a digital secure certificate is installed on your server 610

How to get and use a digital secure certificate 612

How to get a digital secure certificate 612

How to work with certificates using IIS 7 614

How to work with certificates using earlier versions of IIS 616

How to use a secure connection 618

How to request a secure connection 618

How to force a page to use a secure connection 620

A Halloween Store application that uses SSL 622

The operation ofthe Halloween Store application 622

The code for the Halloween Store application 622

Chapter 19 How to authenticate and authorize users

An introduction to authentication 628

Three types of authentication 628

How forms-based authentication works 630

How to set up authentication and authorization 632

How to start the Web Site Administration Tool 632

How to enable forms-based authentication 634

How to create and manage roles 636

How to create and manage users 638

How to create and manage access rules 640

How to modify the membership and role provider 642

How to use the login controls 644

How to use the Login control 644

How to use the LoginStatus and LoginName controls 646

How to use the CreateUserWizard control 648

How to use the PasswordRecovery control 650

How to use the ChangePassword control 652

How to use the LoginView control 654

The Authentication application 656

The pages 656

The directory structure 660

The access rules 660

The web.config files 662

Chapter 20 How to use email, custom error pages,and back-button control

How to send email 666

An introduction to email 666

How to install an SMTP server 668

How to create an email message 670

How to send an email message 672

How to add an attachment to an email message 674

How to create an HTML message 676

Page 11: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

Expanded contents

How to use custom error handling 678

An introduction to custom error handling 678

How to get and use the Exception object for an error 680

How to code methods that redirect to a custom error page 682

The code for a custom error page 684

How to handle HTTP errors with the web.config file 686

How to handle the back-button problem 688

An introduction to the back-button problem 688

How to disable browser page caching 690

How to use timestamps to avoid the back-button problem 692

Chapter 21 How to use AJAX

An introduction to AJAX 696

AJAX concepts 696

How AJAX works 698

An introduction to ASP.NET AJAX 700

How ASP.NET AJAX works 700

The ASP.NETAJAX server controls 702

The ASP.NET AJAX Control Toolkit 704

How to use the ASP.NET AJAX server controls 706

How to use the ScriptManager control 706

How to use the ScriptManagerProxy control 708

How to use the UpdatePanel control 710

How to use the Timer control 712

How to use the UpdateProgress control 714

An application that uses AJAX 716

The Shout Box application 716

The Shoutltem class 718

The ShoutltemList class 718

The aspx file 720

The code-behind file 724

An introduction to jQuery 726

The core jQuery library 726

The jQuery UI library 726

HowjQuery AJAX works 728

Chapter 22 How to configure and deploy ASP.NET 4 applicationsHow to configure an ASP.NET application 732

How to use the Web Site Administration Tool 732

How to use the US Management Console with Windows 7 or Windows Vista 734

How to use the US Management Console with Windows XP 736

How to deploy an ASP.NET application 738

Three ways to deploy an ASP.NET application 738

How to use the Copy Web Site command for XCopy deployment 740

How to use the Publish Web Site command for precompiled deployment 742

How to use the aspnet_compiler command for precompiled deployment 744

How to create a Web Setup project 746

How to create and use a Setup program 748

Page 12: Murach's ASP.NET 4 web programming with C 2010 · Chapter7 Howto usethevalidation controls Anintroductiontothevalidation controls 254 Howto usethe validation controls 254 Commonvalidatorproperties

XVi Expanded contents

Chapter 23 An introduction to WCF services

Basic concepts and terms 752

How WCF services work 752

An introduction to bindings 754

How to create a WCF service 756

How to start a WCF service library 756

How to develop the code for a WCF service library 758

The code for a WCF service that gets product information 760

The configuration file for the WCF service 760

How to test a WCF service 764

How to create a web site that hosts a WCF service library 766

How to start a host web site 766

How to add a reference to a service library 766

The configuration files for the host web site 768

How to display information about the service in a browser 770

How to create a web site that consumes a WCF service 772

How to add a service reference to a client web site 772

How to consume a WCF service 774

Appendix A How to install and use the software

and downloadable files

How to download and install the files for this book 778

How to install IIS under Windows 7 or Windows Vista 780

How to install IIS under Windows XP 782

How to install Visual Studio 2010 784

How to install and use SQL Server 2008 Express 786

How to create the Halloween database 788

How to use the downloaded web applications 790

Appendix B How to work with web applications using IIS

under Windows 7 and Windows Vista

How to create an IIS virtual directory or application 794

How to set the default page for a web site 796

How to force a page to use a secure connection 798

How to work with application pools 800

Appendix C How to work with web applications using IIS

under Windows XP

How to create a virtual directory 804

How to set the default page for a web site 806

How to force a page to use a secure connection 808