Create the Login Page
Create a new page, remembering to hook it to the Master Page as described earlier in this chapter. Name the new page Login.aspx. You'll define the layout of the new page with HTML tables rather than CSS. It is usually preferable to use CSS in web interface development these days, but in this case we feel it will be easier for you to visualize how all the parts come together if you use tables. Insert the following snippet of code into Login.aspx, placing it inside the content placeholder tag...
Root Elements
Root elements are special derivations of panel elements. They serve as the fundamental containers for pages. Every page requires exactly one root element. In the next chapter, when we build an application with Visual Studio, you will notice that the default root element is Grid. It is not uncommon for other panel elements e.g., StackPanel, DockPanel, or Canvas, as well as Page and Window to serve as root elements. The root element must contain a reference to the namespace needed by the other...
Applying AJAX ListMania
This chapter will walk you through a significant AJAX-enhanced ASP.NET application to demonstrate how the various AJAX tools can enrich a real-world application. The application you'll build is a To-Do List Manager, which will consist of two .aspx pages. The first is the login page shown in Figure 6-1. This page allows users to access their personal to-do lists by entering an email address and a password, then clicking the sign-in button. New users can create to-do lists by clicking the Need To...
The MVC Pattern
Wikipedia attributes the Model-View-Controller architectural pattern to Trygve Mikkjel Heyerdahl Reenskaug, who developed it in 1979 while working on Smalltalk at Xerox PARC.
Adding the Shopping Cart
To finish the first page, you only need to add the shopping cart and the associated buttons. You want to offer the user the ability, having chosen a picture, to purchase a 5 x 7 photo, a sweatshirt, or a holiday card. Begin by adding the shopping cart template and triggers to Window.Resources lt -- SHOPPING CART TEMPLATE -- gt lt Style x Key ShoppingCartStyle TargetType x Type ListBox gt lt Setter Property Template gt lt Setter.Value gt lt ControlTemplate TargetType x Type ListBox gt lt Border...
Validating the Credit Card
When the user clicks the Process my credit card button, you'd like to validate the credit card number before submitting the information to the credit card company. You'll do so using the Luhn algorithm also known as the modulus 10 algorithm , created by IBM scientist Hans Peter Luhn and described in U.S. Patent 2,950,048, filed on January 6, 1954 and granted on August 23, 1960 according to Wikipedia . To accomplish this, take the following steps 1. Create a new business class,...
DataContext
At this point, you've told the Title control that it will bind to the Title property, but you haven't told it which object to bind to. The DataContext object is the specific book, which is chosen at runtime and assigned to the DataContext property of the framework element in this case, the TextBlock so that it knows I get the Title from this book. DataContext objects can be inherited down the UI tree. Thus, you can set the DataContext for a Grid, and all the controls in that Grid will have...
Partial Page Rendering
To implement partial page rendering on your page, you must set the ScriptManager's EnablePartialRendering property to true the default , either declaratively or pro-grammatically, in or before the page's init event handler. You then place UpdatePanel objects on your page, and each UpdatePanel can be updated individually, without updating other panels and without a postback of the entire page. From a practical programming point of view, this is very simple you drag a ScriptManager onto the page...
Nesting
Switching gears for a moment, it is possible and legal to nest one control or graphic element within another. This allows you to place, for example, a StackPanel inside a Button, and then place other controls or graphics within that StackPanel. Either on its own or used in conjunction with templates and styles, this is a very powerful technique for making combined, nearly custom controls on the fly. In the next example, we'll put a horizontally oriented StackPanel inside a button. We'll then...
Creating Properties for Each Table
As you can see, you begin by creating an instance of the DataContext object you asked the tool to generate AdventureWorksAddressDataContext dc new AdventureWorksAddressDataContext When you use the designer, one of the things it does besides creating the DataContext class is define a property for each table you've placed in the designer in this case, Customer, Address, and CustomerAddress. It names those properties by making the table names plural. Therefore, the properties of...
Panel Elements
A panel element is a container, designed to support the layout and placement of elements on a page. Panels come in several different shapes and sizes. Depending on how you exercise them, they are useful for laying out different types of elements. As an example, open up XAMLPad and type the following broken code into the code window replacing whatever code was already there Title My Window Height 300 Width 300 gt lt Grid Name AGrid Background AntiqueWhite gt lt Window gt As you can see in Figure...
Services Are Autonomous
SOA services are expected to run in the wild world of decoupled systems. A well-designed service should stand alone and be totally independent and relatively failsafe. As the service topology is almost guaranteed to evolve over time, and there is no presiding authority, you should plan to meet this goal through autonomous design. Here are some points to keep in mind If Murphy Anything that can go wrong will go wrong designed a service, he would do everything he could to isolate that service...
Creating a CheckOut Application in Visual Studio
For the next example, you're going to combine XAML and a business class to display a simple shopping cart, as shown in Figure 3-17. You will populate the listbox by binding to a data source you'll declare in the XAML. Fire up Visual Studio and create a new WPF application named CheckOut. Begin by creating a new class, ShoppingCartItem.cs, as shown in Example 3-13. Example 3-13. ShoppingCartItem.cs using System using System.Collections.Generic using System.Linq using System.Text this.Item...
Adding Stylesheets to Extender Controls
To distinguish the instructional text from text entered by the user, you can add a stylesheet to format the watermark text. You do so by adding the WatermarkCssClass attribute. Begin by adding to your project a stylesheet called TextBoxWatermarkStyle.css .unwatermarked height l8px width l48px font-weight bold background-color FFFFFF color 000000 .watermarked height 20px width l50px padding 2px 0 0 2px border 1px solid BEBEBE background-color FFFFCC color 666666 To add this stylesheet to your...
StackPanel and DockPanel
The first step is to divide the window into three content areas using StackPanel and DockPanel. Begin by creating a Window element in XAMLPad. Give it a title of Employee Directory Title Employee Directory Height 480 Width 640 gt Then insert a Grid element along with the DockPanel that will contain the three content areas lt DockPanel LastChildFill False gt Grid is a souped-up form of StackPanel that allows you to orient your layout both horizontally and vertically. Be careful not to confuse...
Creating a Sample ASPNET Application
Launch Visual Studio 2008 as the Administrator, select File New Web Site, and create a new ASP.NET Web Site as shown in Figure 14-12 . You will want to locate the site in your dedicated directory C 3.5 CardSpaces and select Visual C as the language. Also make sure you have selected .NET Framework 3.5 in the drop-down list in the top-right corner. The first thing to do with your new application is add a new ASP.NET folder called App_Code. Inside this folder, you'll add two classes from Microsoft...
Lambda Expressions in LINQ
Lambda expressions can be used to define inline delegates. In the following expression customer gt customer.FirstName Donna the lefthand operand, customer, is the input parameter, and the righthand operand is the lambda expression. In this case, it checks whether the customer's FirstName property is equal to Donna. This lambda expression is passed into the Where method to perform this comparison operation on each customer in the customer list. Queries defined using extension methods are called...
Create the ToDo List Page
Now you're ready to get cracking on the to-do list that will display the items in the database and allow the user to add new items. Start by creating a new page named it ToDo.aspx. To ensure that it uses the Master Page you created earlier ListManager. master , check the Select master page option, as seen in Figure 6-6. Language visual C r 0 Place code in separate file Figure 6-6. Be sure to check Select master page Drag and drop a ReorderList control into the content placeholder section of the...
About Windows CardSpace
The Windows CardSpace software ships with Microsoft's .NET 3.5 Framework. CardSpace functions as both an identity selector a platform service for user-centric identity management and an identity provider a producer of assertions about the authenticity of an identity . It creates and stores references to a user's digital identities and allows the user to present his identity of choice in the form of an information card. Information cards appear on the screen very much like credit cards or other...
MasterDetail Records
One of the most common and powerful data representations is the master detail or order detail record. A classic example is looking at recent orders on Amazon.com mine are shown in Figure 3-21. W Delivery estimate March 7, 2007 1 of I Am a Strange Loop W Delivery estimate September 1, 2006 1 package via DHL Second Day 1 of A Madman Dreams of Turing Machines Sold by Amazon.com Order Date December 11, 2006 order- i - - Order Recipient Jesse Liberty V Delivery estimate December 13, 2006 1 package...
A Factory Method Example
The ultimate goal of this pattern is to encapsulate the creation of objects. For illustration purposes, you'll build a very pedestrian 20th-century car factory. Each Car class will use an overridden factory method to assign itself the features of its particular subclass. To start with, consider an abstract Car class private List lt Feature gt features new List lt Feature gt Constructor invokes factory method public List lt Feature gt Features The Money Method Factory Method public abstract void...
The Animation Storyboard
The first part of creating an animated user experience is deciding what will be animated, how it will be animated, and in what order the animation will occur. The more common name for this collection of information is a storyboard. Just for fun, in this example you're going to mock up a splash page for an O'Reilly book. You'll have some text, and some branding in the form of a red gradient opaque banner. And what example would be complete without a hexatarsier Figure 2-17 Figure 2-17. The...
An Observer Example
Let's build a little observer application for dealing with flight departures and air traffic control. There will be four pattern participants in this example The subject knows its observers and provides an interface for attaching and detaching observers. Any number of observer objects may observe a subject. The concrete subject stores the state of interest to concrete observer objects and sends appropriate notifications based on state changes. The observer defines the updating interface for...
The Observer PatternPublish and Subscribe
As you might guess from its name, the Observer pattern is used to observe the state of an object. A variant on this pattern is Publish and Subscribe, where the observed object publishes some event or events e.g., a clock says I announce every second and other objects the observers subscribe to those events. To keep things simple, we'll refer to the two patterns together as the Observer pattern it really is just a matter of perspective are you observing me, or am I publishing my events for you...
Animation Overview
We'll go into animation in more detail in the next chapter, but we want to give you a taste now of how much you can do with XAML. Some of the concepts illustrated here aren't discussed fully until the next chapter. Bear with us they'll be made clear soon. Two techniques are used for animation. In the first, known as From To By animation, you transition from a starting to an ending value these are called the target values . You can specify either an endpoint from here to there or a By property...
Displaying the Selected Image
You can add a display of the selected image with just a couple of small changes. To begin, just below the ListBox, add an Image control lt Image Name CurrentPhoto Grid.Row 3 Grid.Column 1 Margin 10 This depends on two things. The first is an OnMouseDown event handler, which you can stub out in Window1.xaml.cs private void OnMouseDown object sender, MouseButtonEventArgs e The second is setting the CurrentPhoto when the user clicks in the image slider private void PhotoListSelection object...
Create a DataHelper Class
In this section, you are going to talk the database more. The code that you used earlier in will turn out to be very handy here. Rather than cutting and pasting, you need to refactor Right-click on your web site in the Solution Explorer and select Add ASP.NET Folder App_Code, as seen in Figure 6-17. Figure 6-17. Adding the ASP.NET App_Code folder Figure 6-17. Adding the ASP.NET App_Code folder Now, add a C class to it called DataHelper.cs to the App_Code folder you just added to your project....
UDDI Who Is Out There and What Can They Do for Me
The Universal Description, Discovery, and Integration UDDI registry has made the process of finding web services infinitely easier. UDDI is a platform-independent, XML-based registry that allows service vendors to list themselves on the Internet. As an open industry initiative, UDDI is sponsored by the Organization for the Advancement of Structured Information Standards OASIS . UDDI enables businesses to publish service listings, discover one another's services, and define how the services or...
Understanding the Identity Metasystem
The main goal of the Identity Metasystem is to allow people to have a set of different identities, each of which may reveal more or less information than the others. It was designed as an interoperable identity-delivery vehicle based on multiple underlying technologies. It allows for multiple implementations as well as multiple providers. With this approach, customers can continue to use their existing identity-infrastructure investments. Then, when the time comes, they can choose the identity...
Adding the AdventureWorksLT Database
The rest of the examples in this chapter use the SQL Server 2005 AdventureWorksLT sample database, which you can download from http tinyurl.com 2xzkf7. Please note that while this database is a simplified version of the more comprehensive AdventureWorks, the two are quite different. The examples in this chapter will not work with the full AdventureWorks database. Please select the AdventureWorksLT .msi package applicable for your platform 32-bit, x64, or IA64 . If SQL Server is installed in the...
A Better Calendar Control
While the Calendar control provided with ASP.NET is very powerful, it is also painful to use, as each date change causes a postback. An AJAX-based solution using the CalendarExtender is a great alternative with this approach, you can refresh only the TextBox control not the entire page when the date in the CalendarExtender changes. To see this at work, create a new ASP.NET Web Site and name it AJAXCalendar. Open the Toolbox and make sure you have access to all the Toolkit controls, as shown in...
LINQ to SQL Fundamentals
To get started with LINQ to SQL, open Visual Studio 2008 and create a new Console Application named Simple LINQ to SQL. Once the IDE is open, click View and open the Server Explorer. Make a connection to the AdventureWorksLT database and test that connection, as shown in Figure 9-13. Figure 9-13. Testing the connection to AdventureWorksLT Figure 9-13. Testing the connection to AdventureWorksLT The next example illustrates using LINQ. For it to compile, you will need to add a reference to the...
Creating a Word Wheel with AJAX
One of the most-requested features in ASP.NET applications is a word wheel in which the user begins to type in a name or other string and the control shows all the names from our data source that begin with the letters entered as the user types more, the provided list is narrowed. This is painful to do with traditional ASP.NET, as you must make a round trip for each letter that's entered. Clearly, this is a place where AJAX can make all the difference. To provide some data to illustrate how...
ScriptManager
The ScriptManager control is central to integrating AJAX with ASP.NET. The ScriptManager manages the components on a page and is responsible for handling partial page updates. It takes care of loading the ASP.NET AJAX client script libraries into the browser, and it's responsible for using proxy objects so that you can access web service methods from JavaScript. AJAX came to ASP.NET by way of JavaScript programmers. These programmers' primary concern is with how they can improve the performance...
Create the Application Master Page
First, create the Application Master Page. This will be used to hold the ScriptManager, as well as the CSS information for the application. Think of it as a donut the request response loop will insert the content from the other pages into the donut-hole in the middle of this master page. To do this, click on your web site's Houston, Tranquility Base here. The Eagle has landed, - Windows Internet Explorer l _ cd ED . CSi. T , fei http l oca 1 h ost60270 ListMa n i a ToDo. aspx j Houston,...
Creating the ToDo List Manager
Begin by creating a new C web application, as you did in the previous chapter. Choose New Web Site from the File menu, and select ASP.NET Web Site from the Templates section. Name the application ListMania. Figure 6-1. The login registration page Figure 6-1. The login registration page We'll build this application in stages you'll get parts of it working and then add on more parts, successively approximating the final product shown in the preceding figures. To save you a bit of work upfront,...
Personalizing the ToDo List
It would be nice to allow various members of your family or office to keep to-do lists, and to separate the lists based on the users' IDs. So next, you'll create a login form to ask the user to provide an email address and a password. We the authors hate being shunted off to a separate page to register, so we'll put the registration form right on the login page. Of course, you don't want the user to see the registration form unless it's needed, so you'll hide it in a collapsible panel that will...
Creating the MVC application
Open Visual Studio and create a new ASP.NET MVC Web Application called creatively ASPMVCApplication, as pictured in Figure 8-4. Smart Device Office Database Reporting Test WCF Workflow Database Projects Other Languages Distributed Systems Oth er P roj ect Types Test Projects Visual Studio installed templates Jp Windows Forms Application Class Library bjj5ASP.NET 3.5 Extensions Web Application k f ASP.NET Web Application ASP.NET Web Service Application jgjWPF Application WPF Browser Application...
Simultaneous Animations
Your Storyboard need not be restricted to running a single DoubleAnimation, nor need it stop after a single well-defined activity e.g., one complete rotation . You can combine movement vertically with movement horizontally to create diagonal movement, for example, and you can repeat that movement indefinitely, as shown in Example 3-11. Example 3-11. Diagonal movement through paired DoubleAnimations lt Window Title Programming .NET 3.5 Simple LGM Animation Background White Margin 50 gt lt...
Applying Styles Inline
Let's start by adding some inline styling to the TextBlock for the Title prompt lt TextBlock x Name TitlePrompt Text Title VerticalAlignment Bottom HorizontalAlignment Right Grid.Row 0 Grid.Column 0 FontFamily Comic Sans MS FontSize l6 FontWeight Bold Foreground Red gt The effect is shown in Figure 7-20. This is a very simple example, but rest assured that the capabilities of the platform are extensive. Ti la Programming Silverlight Author Jesse Liberty, Tim Heuer Figure 7-20. Adding inline...
StackPanel
A StackPanel like all panels can be used on its own or inside other containers. Later you'll use a StackPanel inside a Button, but for now, we'll show one inside a DockPanel. In this example, we'll create an advertising page for an O'Reilly book. First create the DockPanel, then add two TextBlocks. Dock one to the top of the DockPanel you'll use it to display the O'Reilly logo. Dock the other one to the bottom it will show the copyright and trademark notifications. Here's the code Title...
Using the Visual Studio LINQ to SQL Designer
Rather than working out the data relationships in the underlying database and mapping them in the DataContext manually, you can use the designer built into Visual Studio. This is a very powerful mechanism that makes working with LINQ incredibly simple. To see how it works, first open the AdventureWorksLT database in SQL Server Management Studio Express and examine the Customer, CustomerAddress, and Address tables. Make sure you understand their relationship, which is illustrated in the...
Adding Cropping with the Adorner
There are two steps remaining to finish the first page. The first is to add the rubber-band adorner discussed earlier, using the code detailed in Example 4-1. We'll deal with the second task adding the shopping cart in the next section. Begin by adding a RubberbandAdorner class, which you'll place in a new file called CropUtilities.cs. To tie this into the application, you need to make a few changes in Windowl.xaml. First, add the Crop and Undo buttons to the Grid lt ListBox Style...
Control Presentation
WPF and XAML give you tremendous and precise control pardon the expression over the appearance of controls. To demonstrate, we'll start with a simple button, as shown in Example 3-5. Despite the incredible breadth of the English language, even resorting to the astonishingly useful VisualThesaurus http www.VisualThesaurus.com didn't yield a better word than control to use in this sentence Example 3-5. A simple button lt Window Title Programming .NET 3.5 Adding flavor to controls gt lt StackPanel...
Persisting Your State Machine
It's time to send more events but before you can do that, you need to make sure that you can persist the state of the state machine beyond the simple event transaction. For this, you need some sort of persistence layer to mash up with the workflow. Fortunately, Windows Workflow provides out-of-the-box support for persistence through the SOLWorkflowPersistenceService class. By this point in the book we're assuming that you have some version of Microsoft SQL Server installed. If not, go and get...
Canvas and ViewBox
When discussing simple 2-D graphics, we are particularly fond of using little green men. To get started, you'll use the Canvas layout control, which allows for absolute positioning of child elements. You can greatly enhance this control by placing it inside a Viewbox, which, when used in conjunction with an interactive control such as a Window as shown in Example 3-4 , gives you great control over stretching and scaling of the child elements. Example 3-4. Canvas and ViewBox Little green men lt...
Adorners
The spec for this project states that the user can drag a cropping rectangle within any photograph and then click the Crop button to crop the photo, as shown in Figure 4-3. To accomplish this, you'll need to be able to create and display a rubberband on mouse down and mouse drag, and leave it in place on mouse up activating the Crop button and you'll need to be able to crop the photo to its new rectangle. You'll implement the rubberband as an adorner. Adorners are, essentially, elements that...
Part I Presentation Options
Chapter 1, .NET 3.5 A Better Framework for Building MVC, N-Tier, and SOA Applications This chapter provides a short observation on the real power of .NET 3.5. Chapter 2, Introducing XAML A Declarative Way to Create Windows UIs The single biggest change in the presentation layer that .NET 3.5 provides is the ability to create a desktop-based presentation using a declarative syntax. XAML which originally stood for extensible Application Markup Language is the declarative thread that runs through...






















