+ All Categories
Home > Documents > c#.net introduction

c#.net introduction

Date post: 07-Oct-2015
Category:
Upload: murtaza-habib
View: 218 times
Download: 0 times
Share this document with a friend
Description:
Best For Exams....

of 30

Transcript
  • Table of Contents

    Introduction ........................................................................................................................... xxxv

    Part I: .NET Framework 4.5 and Visual Studio 2012

    Chapter 1: C#.NET Essentials ..................................................................................................... 1 Section I Introduction to .NET ....................................................................................................................... 2 Evolution of .NET ................................................................................................................................................ 2 Benefits of .NET Framework ............................................................................................................................... 2 Overview of .NET Framework 4.5 ...................................................................................................................... 3

    CLR................................................................................................................................................................. 4 CTS ................................................................................................................................................................. 5 Metadata and Assemblies ............................................................................................................................. 6 .NET Framework Class Library .................................................................................................................... 8 BCL ................................................................................................................................................................. 9 Windows Forms........................................................................................................................................... 11 ASP.NET and ASP.NET AJAX .................................................................................................................... 11 ADO.NET ..................................................................................................................................................... 12 WF ................................................................................................................................................................ 13 WPF .............................................................................................................................................................. 13 WCF.............................................................................................................................................................. 14 Windows CardSpace ................................................................................................................................... 16 LINQ ............................................................................................................................................................ 17

    Tools in the .NET Framework 4.5 ..................................................................................................................... 17 New Features of .NET Framework 4.5 ............................................................................................................. 20

    .NET for Windows Store Apps ................................................................................................................... 20 Portable Class Libraries ............................................................................................................................... 20 Core New Features and Improvements ..................................................................................................... 21 MEF .............................................................................................................................................................. 21 Asynchronous File Operations ................................................................................................................... 21 Tools ............................................................................................................................................................. 22 Parallel Computing ..................................................................................................................................... 22 Improvements in Web Application Development ..................................................................................... 22 Networking .................................................................................................................................................. 22

  • Table of Contents

    vi

    Improvements in WPF ................................................................................................................................ 22 Improvements in WCF ................................................................................................................................ 23 Improvements in WF ................................................................................................................................... 23

    Section II Introduction to Visual Studio 2012 IDE ..................................................................................... 24 New Features of Visual Studio 2012 ................................................................................................................. 25

    Project Compatibility ................................................................................................................................... 25 Configuration Changes in ASP.NET Website Templates .......................................................................... 26 Native Support in IIS 7.5 for ASP.NET Routing ........................................................................................ 26 HTML Editor ............................................................................................................................................... 26 JavaScript Editor .......................................................................................................................................... 31 CSS Editor .................................................................................................................................................... 31 Page Inspector.............................................................................................................................................. 35 Publishing .................................................................................................................................................... 36 Support for Developing Windows Store Apps .......................................................................................... 36 Enhanced Cloud Capability ........................................................................................................................ 37 New Tabs in Start Page ............................................................................................................................... 37 ALM and TFS ............................................................................................................................................... 37 Managing the Application Lifecycle ........................................................................................................... 37 Modeling Applications ................................................................................................................................ 37 Developing Applications and Building Communication in a Team ......................................................... 37 Automating and Debugging Builds............................................................................................................ 38 Microsoft Test Manager .............................................................................................................................. 38 Some Miscellaneous Features of Visual Studio 2012 ................................................................................. 38

    Editions of Visual Studio 2012 .......................................................................................................................... 39 Installing Visual Studio 2012............................................................................................................................. 40 Exploring the Visual Studio 2012 IDE .............................................................................................................. 44

    Start Page ..................................................................................................................................................... 45 Menu Bar ...................................................................................................................................................... 45 Toolbar ......................................................................................................................................................... 45 Toolbox......................................................................................................................................................... 46 Code Editor .................................................................................................................................................. 46 IntelliSense ................................................................................................................................................... 47 Designers...................................................................................................................................................... 49 Solution Explorer ......................................................................................................................................... 51 Properties Window ...................................................................................................................................... 52 Object Browser ............................................................................................................................................. 53 Class View.................................................................................................................................................... 54 Server Explorer ............................................................................................................................................ 55 Component Tray .......................................................................................................................................... 56 Output Window .......................................................................................................................................... 56 Task List ....................................................................................................................................................... 57

  • Table of Contents

    vii

    Error List ...................................................................................................................................................... 57 Command Window ..................................................................................................................................... 58 Dynamic Help Window .............................................................................................................................. 58 Manage Styles Window............................................................................................................................... 59

    Basic IDE Operations ......................................................................................................................................... 60 Creating a New Windows Application ...................................................................................................... 60 Saving Code on the Toolbox ....................................................................................................................... 61 Docking the Windows ................................................................................................................................. 63 Switching between the Windows ............................................................................................................... 64 Specifying the .NET Framework Version for Projects ............................................................................... 66 Exporting and Importing IDE Settings ....................................................................................................... 66 Changing the IDE Font and Color .............................................................................................................. 72 Building and Debugging the Projects ......................................................................................................... 74

    Section III C# 5.0 Overview .......................................................................................................................... 77 New Features of C# 5.0 ..................................................................................................................................... 77

    Async and Await ......................................................................................................................................... 77 Caller Information ....................................................................................................................................... 78 Lambda Expressions.................................................................................................................................... 78 LINQ Expressions ........................................................................................................................................ 78 Named Arguments ...................................................................................................................................... 78 Overload Resolution .................................................................................................................................... 78

    Creating a Simple C# 5.0 Console Application ................................................................................................ 78 Section IV Snapshot of .NET Related Technologies .................................................................................. 80 WPF .................................................................................................................................................................... 80 LINQ .................................................................................................................................................................. 81 ADO.NET Entity Framework ........................................................................................................................... 81 ASP.NET AJAX .................................................................................................................................................. 81 Silverlight ........................................................................................................................................................... 81 ASP.NET Web Services ..................................................................................................................................... 81 WCF Services ..................................................................................................................................................... 81 Summary ............................................................................................................................................................ 82

    Part II: C# Programming Language

    Chapter 2: C# Fundamentals .................................................................................................... 83 In Depth............................................................................................................................................................. 84 Identifiers and Keywords .................................................................................................................................. 84 Variables and Constants .................................................................................................................................... 85

    Value Types ................................................................................................................................................. 87 Reference Types........................................................................................................................................... 89 Pointer Types ............................................................................................................................................... 91 Type Conversions ........................................................................................................................................ 92 Boxing and Unboxing .................................................................................................................................. 93

  • Table of Contents

    viii

    Expressions and Operators ............................................................................................................................... 94 Immediate Solutions ........................................................................................................................................ 98 Declaring Variables ........................................................................................................................................... 98 Initializing Variables ....................................................................................................................................... 100 Declaring Constants ........................................................................................................................................ 101 Declaring Nullable Type Variables ................................................................................................................. 101 Using the ?? (Null Coalescing) Operator ........................................................................................................ 102 Specifying the Scope of a Variable .................................................................................................................. 103 Using the Scope Resolution Operator (::) ....................................................................................................... 104 Declaring and Initializing Strings ................................................................................................................... 105 Manipulating Strings ....................................................................................................................................... 105 Converting a Number Type into another Number Type .............................................................................. 107 Converting a String Type to a Number Type ................................................................................................. 108 Converting Two Nullable Types .................................................................................................................... 109 Using the is and as Operators ......................................................................................................................... 110 Determining the Minimum and Maximum Values of Data Types ............................................................... 111 Creating an Enumeration ................................................................................................................................ 112 Declaring Single and Multi-dimensional Arrays ........................................................................................... 113 Iterating Through an Array............................................................................................................................. 115 Creating an Alias ............................................................................................................................................. 117 Summary .......................................................................................................................................................... 118

    Chapter 3: Flow Control and Exception Handling in C# 5.0 Programs ................................. 119 In Depth........................................................................................................................................................... 120 Control Flow Statements ................................................................................................................................. 120

    Selection Statements .................................................................................................................................. 120 Iteration Statements or Loops ................................................................................................................... 122 Jump Statements ........................................................................................................................................ 124

    Exception Handling ......................................................................................................................................... 126 The trycatchfinally Statement ............................................................................................................ 127 The throw Statement ................................................................................................................................. 128

    Checked and Unchecked Statements .............................................................................................................. 128 Immediate Solutions ...................................................................................................................................... 129 Using the if Statement ..................................................................................................................................... 129 Using Nested if Statements ............................................................................................................................. 129 Using the switch Statement ............................................................................................................................. 130 Using Fall-through Switch Statement ............................................................................................................. 132 Using the while Loop ...................................................................................................................................... 133 Using the dowhile Loop .............................................................................................................................. 134 Using the for Loop ........................................................................................................................................... 135

  • Table of Contents

    ix

    Using the foreach Loop ................................................................................................................................... 137 Using Nested for Loops................................................................................................................................... 138 Creating an Infinite Loop ................................................................................................................................ 139 Using the goto Statement ................................................................................................................................ 140 Breaking a Loop ............................................................................................................................................... 141 Using the continue Statement ......................................................................................................................... 143 Handling an Exception .................................................................................................................................... 143 Throwing an Exception ................................................................................................................................... 144 Using the checked and unchecked Statements .............................................................................................. 145 Summary .......................................................................................................................................................... 146

    Chapter 4: Namespaces, Classes, Objects, and Structs ....................................................... 147 In Depth........................................................................................................................................................... 149 Exploring Namespaces .................................................................................................................................... 149 Exploring Classes and Objects ........................................................................................................................ 152

    Syntax of a Class ........................................................................................................................................ 152 Methods as Class Members ....................................................................................................................... 152 Access Modifiers ........................................................................................................................................ 154 Objects ........................................................................................................................................................ 154 Constructors and Destructors ................................................................................................................... 155 Static Classes and Static Class Members .................................................................................................. 156 Properties ................................................................................................................................................... 157 Indexers ...................................................................................................................................................... 159

    Exploring Structs ............................................................................................................................................. 160 Syntax of a Struct ....................................................................................................................................... 160 Access Modifiers for Structs ...................................................................................................................... 161

    Immediate Solutions ...................................................................................................................................... 162 Creating a Namespace ..................................................................................................................................... 162 Adding a Reference to the Namespace ........................................................................................................... 163 Accessing a Predefined Namespace through the using Directive................................................................. 165 Creating a Class ............................................................................................................................................... 166 Declaring a Partial Class ................................................................................................................................. 167 Creating an Object ........................................................................................................................................... 167 Using this Keyword ......................................................................................................................................... 169 Creating an Array of Objects........................................................................................................................... 170 Using a Method with Parameters ................................................................................................................... 172 Using a Method with Arguments ................................................................................................................... 173 Passing a Reference Argument to a Method .................................................................................................. 174 Passing an Object as an Argument to a Method ............................................................................................ 175 Returning a Value from a Method .................................................................................................................. 177 Creating a Partial Method ............................................................................................................................... 177

  • Table of Contents

    x

    Using a Parameterized Constructor in a Class ............................................................................................... 179 Creating a Copy Constructor .......................................................................................................................... 179 Calling the Destructor of a Class .................................................................................................................... 181 Creating a Static Class ..................................................................................................................................... 181 Using a Static Method in Classes .................................................................................................................... 182 Assigning and Retrieving Values Using a Property ...................................................................................... 183 Using Object Initializers .................................................................................................................................. 184 Retrieving Values using a Read-Only Property ............................................................................................. 185 Creating a Static Property ............................................................................................................................... 186 Creating an Anonymous Type ........................................................................................................................ 187 Using an Indexer.............................................................................................................................................. 188 Using a String Indexer ..................................................................................................................................... 189 Using Nested Classes ...................................................................................................................................... 190 Using a Struct ................................................................................................................................................... 191 Summary .......................................................................................................................................................... 192

    Chapter 5: Object-Oriented Programming in C# 5.0 .............................................................. 193 In Depth........................................................................................................................................................... 194 Encapsulation .................................................................................................................................................. 194 Inheritance ....................................................................................................................................................... 195

    Inheritance and Constructors .................................................................................................................... 195 Sealed Classes and Sealed Methods ......................................................................................................... 196 Extension Methods .................................................................................................................................... 196

    Polymorphism ................................................................................................................................................. 197 Compile Time Polymorphism/Overloading ........................................................................................... 197 Runtime Polymorphism/Overriding ....................................................................................................... 200

    Abstraction ....................................................................................................................................................... 200 Abstract Classes ......................................................................................................................................... 201 Abstract Methods ...................................................................................................................................... 201

    Interfaces .......................................................................................................................................................... 202 Syntax of Interfaces ................................................................................................................................... 202 Implementation of Interfaces .................................................................................................................... 203 Interfaces and Inheritance ......................................................................................................................... 203

    Immediate Solutions ...................................................................................................................................... 205 Inheriting a Class ............................................................................................................................................. 205 Creating a Sealed Class ................................................................................................................................... 206 Using an Extension Method ............................................................................................................................ 207 Implementing Encapsulation Using Accessors and Mutators ...................................................................... 208 Implementing Encapsulation Using Properties ............................................................................................. 209 Implementing Operator Overloading ............................................................................................................ 210 Overloading a Method .................................................................................................................................... 212

  • Table of Contents

    xi

    Overloading an Indexer .................................................................................................................................. 213 Overloading the new Operator ....................................................................................................................... 214 Overriding a Base Class Method .................................................................................................................... 215 Implementing an Interface .............................................................................................................................. 216 Inheriting an Interface ..................................................................................................................................... 217 Summary .......................................................................................................................................................... 218

    Chapter 6: Pointers, Delegates, and Events .......................................................................... 219 In Depth........................................................................................................................................................... 220 Pointers ............................................................................................................................................................ 220

    Declaring Unsafe Code .............................................................................................................................. 220 Declaring Pointers ..................................................................................................................................... 221 Performing Arithmetic Operations on Pointers ....................................................................................... 221 Converting Pointers................................................................................................................................... 222

    Delegates .......................................................................................................................................................... 223 Creating and Using Delegates .................................................................................................................. 223 Multicasting with Delegates ..................................................................................................................... 224 Exploring Covariance and Contravariance .............................................................................................. 224 Exploring Anonymous Methods with Delegates ..................................................................................... 225

    Events ............................................................................................................................................................... 226 Event Sources ............................................................................................................................................. 226 Event Handlers .......................................................................................................................................... 227 Events and Delegates ................................................................................................................................ 227 Multiple Event Handlers ........................................................................................................................... 229

    Immediate Solutions ...................................................................................................................................... 230 Creating Pointer to int Data Type ................................................................................................................... 230 Dereferencing Pointers .................................................................................................................................... 231 Using Pointers to Arrays ................................................................................................................................. 232 Using Pointers to Structures ........................................................................................................................... 233 Using Pointers to a Pointer.............................................................................................................................. 234 Subtracting Pointers ........................................................................................................................................ 235 Converting a Pointer Type to another Pointer Type ...................................................................................... 236 Using the fixed Statement ............................................................................................................................... 237 Creating a Delegate ......................................................................................................................................... 238 Declaring and Instantiating a Delegate .......................................................................................................... 240 Creating Multicast Delegates .......................................................................................................................... 242 Implementing Covariance ............................................................................................................................... 244 Implementing Contravariance ........................................................................................................................ 245 Using Anonymous Methods to Instantiate Delegates ................................................................................... 246 Creating Events................................................................................................................................................ 247 Chaining Events............................................................................................................................................... 248

  • Table of Contents

    xii

    Working with an Event Source ....................................................................................................................... 249 Firing an Event ................................................................................................................................................ 252 Summary .......................................................................................................................................................... 254

    Chapter 7: Dynamic Data Type and Dynamic Language Runtime (DLR) .............................. 255 In Depth........................................................................................................................................................... 256 Understanding the Dynamic Data Type ........................................................................................................ 256 Converting the Data Types ............................................................................................................................. 257 Exploring Dynamic Language Runtime ......................................................................................................... 258

    Advantages of DLR ................................................................................................................................... 258 Architecture of DLR .................................................................................................................................. 259

    Understanding the ExpandoObject and DynamicObject Classes ................................................................. 260 Immediate Solutions ...................................................................................................................................... 261 Using Dynamic Data Type .............................................................................................................................. 261 Converting Data Types ................................................................................................................................... 262 Using the ExpandoObject Class ...................................................................................................................... 263 Using the DynamicObject Class ...................................................................................................................... 264 Summary .......................................................................................................................................................... 266

    Part III: Windows Forms and Windows Presentation Foundation (WPF)

    Chapter 8: Introducing Windows Presentation Foundation .................................................. 267 In Depth........................................................................................................................................................... 268 New Features of WPF 4.5 ................................................................................................................................ 268

    The Ribbon Control ................................................................................................................................... 269 Support for Validating Data Synchronously and Asynchronously ........................................................ 269 Support for Binding to Types that Implement ICustomTypeProvider ................................................... 269 Support for Fetching Binding Information............................................................................................... 269 Data Binding to Static Properties .............................................................................................................. 270 Support for Accessing Collections on a Non-UI Thread ......................................................................... 270 Support for Automatically Updating a Source of a Data Binding .......................................................... 270 New VirtualizingPanel Features ............................................................................................................... 270 Support for Implementing Weak Reference to an Event ......................................................................... 270 New Methods Defined in the Dispatcher Class ....................................................................................... 271 Support for the Use of Markup Extensions for Events ............................................................................ 271 Support for Rearrangement of Data on Modification (Live Shaping)..................................................... 271 Improved Performance when Displaying Large Sets of Grouped Data ................................................. 271 Support for the Validation of DataContext Object ................................................................................... 271

    WPF 4.5 Architecture ....................................................................................................................................... 271 PresentationFramework ............................................................................................................................ 272 PresentationCore ....................................................................................................................................... 272 WindowsBase ............................................................................................................................................ 272

  • Table of Contents

    xiii

    MIL or Milcore ........................................................................................................................................... 272 WPF 4.5 Class Hierarchy ................................................................................................................................. 273

    The System.Windows.Threading.DispatcherObject Class ...................................................................... 273 The System.Windows.DependencyObject Class ...................................................................................... 274 The System.Windows.Freezable Class ..................................................................................................... 274 The System.Windows.Media.Visual Class ............................................................................................... 274 The System.Windows.UIElement Class ................................................................................................... 275 The System.Windows.FrameworkElement Class .................................................................................... 275 The System.Windows.Controls.Control Class ......................................................................................... 275 The System.Windows.Controls.Panel Class ............................................................................................. 275 The System.Windows.Shapes.Shape Class .............................................................................................. 276 The System.Windows.ContentElement Class .......................................................................................... 276

    WPF 4.5 Application Model ............................................................................................................................ 276 Types of WPF Applications....................................................................................................................... 276 The Application Class ............................................................................................................................... 283

    Exploring the WPF 4.5 Designer Interface ..................................................................................................... 285 Design View ............................................................................................................................................... 286 XAML View ............................................................................................................................................... 289 Split View Bar ............................................................................................................................................ 289 Solution Explorer ....................................................................................................................................... 291 Properties Window .................................................................................................................................... 291 Toolbox....................................................................................................................................................... 292 Document Outline Window ...................................................................................................................... 293

    Using XAML in WPF 4.5 Applications ........................................................................................................... 294 XAML Elements......................................................................................................................................... 294 Namespaces and XAML ............................................................................................................................ 295 XAML Property Syntax ............................................................................................................................. 296 Markup Extensions .................................................................................................................................... 297

    WPF Properties ................................................................................................................................................ 298 Dependency Properties ............................................................................................................................. 298 Attached Properties ................................................................................................................................... 306

    WPF Events ...................................................................................................................................................... 308 Routed Events ............................................................................................................................................ 308 Attached Events ......................................................................................................................................... 312 Lifetime of Events ...................................................................................................................................... 313

    Working with Dialog Boxes in WPF Applications ......................................................................................... 315 The MessageBox Class............................................................................................................................... 315 The OpenFileDialog Class ......................................................................................................................... 316 The SaveFileDialog Class .......................................................................................................................... 316 The PrintDialog Class ................................................................................................................................ 316

    Compiling and Running WPF 4.5 Applications ............................................................................................. 317

  • Table of Contents

    xiv

    Immediate Solutions ...................................................................................................................................... 320 Working with WPF Windows ......................................................................................................................... 320 Adding Rows and Columns to a Grid Through XAML ................................................................................ 324 Creating a Dialog Box in a WPF 4.5 Application ........................................................................................... 326

    Using a Message Box ................................................................................................................................. 326 Using the Print Dialog Box ........................................................................................................................ 327

    Working with Custom Routed Events............................................................................................................ 330 Summary .......................................................................................................................................................... 332

    Chapter 9: Working with WPF 4.5 Controls, Resources, Styles, Templates, and Commands ..................................................................................................... 333

    In Depth........................................................................................................................................................... 334 WPF 4.5 Controls ............................................................................................................................................. 334

    Container Controls .................................................................................................................................... 334 Simple Controls ......................................................................................................................................... 342 Content Controls ....................................................................................................................................... 349 Headered Content Controls ...................................................................................................................... 360 ItemsControl Control ................................................................................................................................ 363 HeaderedItems Controls ........................................................................................................................... 370 Miscellaneous Controls ............................................................................................................................. 372

    Resources ......................................................................................................................................................... 380 Static Resources ......................................................................................................................................... 380 Dynamic Resources ................................................................................................................................... 381

    Styles and Templates ....................................................................................................................................... 381 Styles in WPF 4.5 ....................................................................................................................................... 381 Templates ................................................................................................................................................... 382

    Triggers ............................................................................................................................................................ 383 Property Triggers....................................................................................................................................... 383 Event Triggers............................................................................................................................................ 384

    WPF Commands .............................................................................................................................................. 384 Command Sources ..................................................................................................................................... 384 Command Targets ..................................................................................................................................... 385 Command Binding .................................................................................................................................... 385

    Interoperability between Windows Forms and a WPF 4.5 Application ....................................................... 385 Immediate Solutions ...................................................................................................................................... 386 Using WPF Controls ........................................................................................................................................ 386

    Using the Calendar and DatePicker Controls .......................................................................................... 386 Adding Controls through the XAML Code ............................................................................................. 387 Adding Controls through the Code-Behind File...................................................................................... 388 Using Dynamic Layout of Controls .......................................................................................................... 389 Setting the Absolute Position of Controls ................................................................................................ 391

  • Table of Contents

    xv

    Adding Borders to Controls ...................................................................................................................... 392 Using the PasswordBox Control ............................................................................................................... 393 Creating a Scrollable Area in a WPF Application .................................................................................... 393 Using the Slider Control ............................................................................................................................ 394 Using the Viewbox Control ....................................................................................................................... 395 Assigning the Access Key for Controls .................................................................................................... 395 Using the Expander Control ..................................................................................................................... 397 Using the NavigationWindow and Frames Controls .............................................................................. 398

    Using the Resources, Styles, and Templates .................................................................................................. 399 Accessing Resources from Code ............................................................................................................... 399 Using Dynamic Resources ........................................................................................................................ 400 Setting Styles through Resources .............................................................................................................. 401 Extending an Existing Style ...................................................................................................................... 402 Using DataTemplate to Change the Appearance of the Content of Control .......................................... 403 Using ControlTemplate ............................................................................................................................. 404 Using the DataTemplate Template ........................................................................................................... 405 Handling Events in Styles Using the EventSetter Class .......................................................................... 406

    Using Triggers ................................................................................................................................................. 408 Setting the Value of Properties using Triggers ........................................................................................ 408 Performing Actions using Triggers .......................................................................................................... 408

    Using WPF Commands with Controls ........................................................................................................... 411 Hosting a Windows Forms Controls in a WPF Application ......................................................................... 411 Hosting a WPF Control in a Windows Forms Application ........................................................................... 412 Summary .......................................................................................................................................................... 414

    Part IV: ASP.NET 4.5 and Silverlight 5.0

    Chapter 10: Introducing ASP.NET 4.5 and Web Forms ......................................................... 415 In Depth........................................................................................................................................................... 416 New Features in ASP.NET 4.5 ........................................................................................................................ 416

    ASP.NET Core Services ............................................................................................................................. 416 ASP.NET Web Forms ................................................................................................................................ 418 ASP.NET Web Pages 2 .............................................................................................................................. 419

    Describing the ASP.NET Technologies .......................................................................................................... 419 MVC Framework ....................................................................................................................................... 419 ADO.NET Entity Framework ................................................................................................................... 419 ADO.NET Data Services Framework ....................................................................................................... 420 The Silverlight Technology ....................................................................................................................... 420 Dynamic Data Framework ........................................................................................................................ 420 ASP.NET Web API .................................................................................................................................... 420

    Describing the ASP.NET Life Cycle ................................................................................................................ 420 Life Cycle of an ASP.NET Application on IIS 7.5..................................................................................... 421

  • Table of Contents

    xvi

    Life Cycle of an ASP.NET Web Page ........................................................................................................ 422 Specifying a Location for a Web Application ................................................................................................. 424

    File System ................................................................................................................................................. 424 HTTP .......................................................................................................................................................... 425 FTP ............................................................................................................................................................. 429

    Structure of an Application ............................................................................................................................. 430 The Application Domain ........................................................................................................................... 430 The Application Lifetime .......................................................................................................................... 431 The Application Directory Structure ........................................................................................................ 431

    File Types in ASP.NET Web Sites ................................................................................................................... 432 Compilation in ASP.NET 4.5 ........................................................................................................................... 434 Dynamic Compilation in ASP.NET 4.5........................................................................................................... 435

    Compiling on First Request ...................................................................................................................... 435 Recompiling on Change ............................................................................................................................ 435 Compilation Dependencies ....................................................................................................................... 435 Compilation Output .................................................................................................................................. 435 Multiple Language Support ...................................................................................................................... 436 Optimizing Dynamic Compilation ........................................................................................................... 436 Disadvantages of Dynamic Compilation ................................................................................................. 436

    ASP.NET 4.5 Coding Models .......................................................................................................................... 436 Single-File Page Model .............................................................................................................................. 437 Code-Behind Page Model.......................................................................................................................... 438

    ASP.NET 4.5 Page Directives .......................................................................................................................... 439 The @ Page Directive ................................................................................................................................. 440 The @ Control Directive ............................................................................................................................ 440 The @ Import Directive ............................................................................................................................. 440 The @ Implements Directive ..................................................................................................................... 440 The @ Register Directive ........................................................................................................................... 440 The @ Assembly Directive......................................................................................................................... 440 The @ Master Directive ............................................................................................................................. 441 The @ PreviousPageType Directive .......................................................................................................... 441 The @ MasterType Directive ..................................................................................................................... 441 The @ OutputCache Directive ................................................................................................................... 441 The @ Reference Directive ......................................................................................................................... 441 The @WebHandler Directive .................................................................................................................... 441

    Immediate Solutions ...................................................................................................................................... 442 Creating a New Web Site ................................................................................................................................ 442

    Using File System based Location ............................................................................................................ 442 Using HTTP-based Location ..................................................................................................................... 444 Using FTP-Based Location ........................................................................................................................ 446

    Setting the Title Bar Text of a Web Form ........................................................................................................ 448

  • Table of Contents

    xvii

    Adding a Background Color to a Web Form ................................................................................................. 449 Adding a Background Image to a Web Form ................................................................................................ 450 Adding Controls to a Web Form..................................................................................................................... 450

    Hiding and Displaying Controls .............................................................................................................. 451 Disabling and Enabling Controls .............................................................................................................. 452 Setting the Captions and Fonts of Controls .............................................................................................. 453 Setting the Tab Order of a Control............................................................................................................ 454 Adding Tool Tips to Controls ................................................................................................................... 455 Specifying Access Characters for Controls ............................................................................................... 455

    Running a Web Application............................................................................................................................ 455 Creating a Multiform Web Application ......................................................................................................... 457 Displaying the Life Cycle of a Page ................................................................................................................ 458 Web Forms Navigation and Cross-Page Posting ........................................................................................... 460 Summary .......................................................................................................................................................... 464

    Chapter 11: Standard Web Server Controls ........................................................................... 465 In Depth........................................................................................................................................................... 466 The Control Class ............................................................................................................................................ 466 The WebControl Class ..................................................................................................................................... 468 The Button Control .......................................................................................................................................... 469 The TextBox Control ........................................................................................................................................ 470 The Label Control ............................................................................................................................................ 471 The HyperLink Control ................................................................................................................................... 472 The LinkButton Control .................................................................................................................................. 472 The Literal Control .......................................................................................................................................... 473 The PlaceHolder Control ................................................................................................................................. 473 The HiddenField Control ................................................................................................................................ 474 The FileUpload Control ................................................................................................................................... 474 The CheckBox Control..................................................................................................................................... 474 The RadioButton Control ................................................................................................................................ 475 The ListBox Control ......................................................................................................................................... 475 The DropDownList Control ............................................................................................................................ 476 The BulletedList Control ................................................................................................................................. 476 The Image Control ........................................................................................................................................... 478 The ImageButton Control ................................................................................................................................ 478 The ImageMap Control ................................................................................................................................... 479 The Table Control ............................................................................................................................................ 480 The Wizard Control ......................................................................................................................................... 480 User Controls and Custom Controls .............................................................................................................. 483 Using CSS in Web Applications ...................................................................................................................... 483

  • Table of Contents

    xviii

    Immediate Solutions ...................................................................................................................................... 484 Using the Button Control ................................................................................................................................ 484 Using the TextBox Control .............................................................................................................................. 485 Using the Label Control .................................................................................................................................. 486 Using the HyperLink Control ......................................................................................................................... 488 Using the LinkButton Control......................................................................................................................... 489 Using the Literal Control................................................................................................................................. 490 Using the PlaceHolder Control ....................................................................................................................... 492 Using the HiddenField Control ...................................................................................................................... 493 Using the FileUpload Control ......................................................................................................................... 494 Using the CheckBox Control ........................................................................................................................... 496 Using the RadioButton Control ...................................................................................................................... 498 Using the ListBox Control ............................................................................................................................... 501 Using the DropDownList Control .................................................................................................................. 505 Using the BulletedList Control ....................................................................................................................... 506 Using the Image Control ................................................................................................................................. 508 Using the ImageButton Control ...................................................................................................................... 509 Using the ImageMap Control ......................................................................................................................... 511 Using the Table Control .................................................................................................................................. 513 Using the Wizard Control ............................................................................................................................... 516 User Controls and Custom Controls .............................................................................................................. 520

    Creating User Controls .............................................................................................................................. 520 Creating Custom Controls ........................................................................................................................ 521

    Using CSS in Web Applications ...................................................................................................................... 523 Summary .......................................................................................................................................................... 528

    Chapter 12: Navigation Controls in ASP.NET 4.5 .................................................................. 529 In Depth........................................................................................................................................................... 530 Using the TreeView Class ............................................................................................................................... 530 The TreeView Control ..................................................................................................................................... 532

    Adding Nodes to a TreeView Control Dynamically................................................................................ 533 Adding Nodes to a TreeView Control Using the DataSource Property ................................................. 533 Adding Nodes to a TreeView Control at Design Time ............................................................................ 534

    Using the Menu Class...................................................................................................................................... 535 The Menu Control ........................................................................................................................................... 537

    Menu Display Properties .......................................................................................................................... 538 Menu Styles................................................................................................................................................ 538

    Using the SiteMapPath Class .......................................................................................................................... 538 The SiteMapPath Control ................................................................................................................................ 540

    Data Retrieval Using the SiteMapPath Control ....................................................................................... 540 SiteMapPath Behaviors ............................................................................................................................. 540

  • Table of Contents

    xix

    SiteMapPath Style ...................................................................................................................................... 541 SiteMapPath Templates............................................................................................................................. 541

    Immediate Solutions ...................................................................................................................................... 542 Creating the TreeView Control ....................................................................................................................... 542 Generating TreeView from a Database .......................................................................................................... 550 Creating Static Menus ..................................................................................................................................... 554 Creating Dynamic Menus ............................................................................................................................... 556 Creating SiteMapPath ..................................................................................................................................... 558 Summary .......................................................................................................................................................... 560

    Chapter 13: Login and Web Parts Controls in ASP.NET 4.5 .................................................. 561 In Depth........................................................................................................................................................... 562 Introducing Login Controls ............................................................................................................................ 562

    The Login Control ..................................................................................................................................... 563 The LoginView Control ............................................................................................................................. 565 The LoginName Control ........................................................................................................................... 567 The LoginStatus Control ........................................................................................................................... 567 The PasswordRecovery Control ............................................................................................................... 569 The ChangePassword Control .................................................................................................................. 571 The CreateUserWizard Control ................................................................................................................ 575

    Introducing Web Parts Controls ..................................................................................................................... 579 The WebPartManager Control .................................................................................................................. 579 The ProxyWebPartManager Control ........................................................................................................ 588 The WebPartZone Control ........................................................................................................................ 589 The CatalogZone Control .......................................................................................................................... 592 The DeclarativeCatalogPart Control......................................................................................................... 593 The PageCatalogPart Control ................................................................................................................... 595 The ImportCatalogPart Control ................................................................................................................ 596 The EditorZone Control ............................................................................................................................ 598 The LayoutEditorPart Control .................................................................................................................. 600 The AppearanceEditorPart Control .......................................................................................................... 602 The PropertyGridEditorPart Control........................................................................................................ 603 The BehaviorEditorPart Control ............................................................................................................... 604 The ConnectionsZone Control .................................................................................................................. 606

    Immediate Solutions ..................


Recommended