Configuring IIS for Your Application

If you want to add Windows CardSpace support to a web site, there are certain things you need to do. One of these involves making sure your site is able to use the Secure Sockets Layer (SSL) you can do this from the IIS Administration application with the easy-to-use GUI. Using IIS7, you'll need to check that everything is properly configured prior to creating your test application 1. Make sure you have created a dedicated directory, such as C 3.5 CardSpaces. 2. Launch the IIS Manager from the...

Page 1Adding Items to the Shopping Cart

With the business classes in place in StoreItems.cs, you're ready to build the first page. Open up Window1.xaml, as shown in Figure 4-4. Now, edit this file to create a slider for the photographs. You'll do this by adapting the image list created in the previous chapter to display the U.S. presidents. In that example you had a Grid with a StackPanel, and inside that was a ListBox with ListBox items. In this case, rather than explicitly naming the items in the listbox, you're going to bind the...

Building an Incident Support State Machine

In the world of customer support, it's generally impossible to know in advance all the rules to apply to a request. Many companies have tried to make the workflow as sequential as possible, with the use of phone-based routing and resolution of issues. However, in many (most ) cases, customer support calls require some amount of ad-hoc decision making by a human being. In this next example, you'll build a state machine that will track a support call from an open to a closed state. Over the life...

Control Elements

Control elements are user-manipulated objects that help with data or user interactions. Controls can be differentiated into five types based on their support of the Content, Header, and Item attributes A simple control does not have Content, Header, or Item attributes. Controls like images, frames, and scroll bars all fall into this category. The next snippet shows an example of an Image control in a window Title Image Height 100 Width 200 > < Grid Name StuffToBuy> < Image Height 33...

Document Elements

Document elements are another interesting aspect of XAML. Most of us are familiar with the first case of the document element, the FixedDocument. This is the traditional what you see is what you get (WYSIWYG) view of a document that we all know and love. The example presented here uses a FlowDocument, which provides much greater flexibility in how the document is rendered and improves user experience. Coupled with a rich set of controls, a flow document can make for a very pleasant reading...

Canvases

The Canvas enables absolute positioning of controls. The default background color for a Canvas is transparent, and the default width and height are 0. Every visible UI control will describe its position on the Canvas by referring to the Canvas's Left and Top properties (as you'll recall from Chapter 3, these are called attached properties). For example, the Button object might use the attached property Canvas.Left to position itself with respect to the left border of its surrounding Canvas <...

W

Adding stylesheet to format text, 158-160 WatermarkCssClass attribute, 158 WCF (Windows Communication Foundation), xi creating a service contract, 343-345 SOA implementation, 339-343 YahooQuotes service (example), 346-364 web page for this book, xvi web services, 5, 332-336 ASP.NET, OrderStatus (example), 368-371 consuming (YahooQuotes example), 355-364 creating WPF client, 357-364 creating and launching (YahooQuotes example), 346-355 creating the service, 348-355 launching the service, 355...

Persist the List

To ensure that changes to the list order persist, you need to create two methods and bind an action to the OnItemReorder property of the ReorderList. First, open up the ToDo.aspx.cs file and make sure you have referenced the following namespaces using System.Web.UI.WebControls.WebParts Now, add a method that will take care of writing updates to your database public void SqlConnection connection, String updateStatement) SqlCommand cmd new SqlCommand(updateStatement, connection) int rowsAffected...

Page 2Validating the Credit Card

The second page, shown in Figure 4-10, is pretty straightforward to lay out. Start by creating the new page, Checkout.xaml. (Be sure to add a new Page, not a new Windows Form Pages are used for WPF, and Windows Forms are used for .NET 2.x.) Once again, let's start simple. You'll add the TextBlock for the header and a Grid to hold the radio buttons for the credit cards, all of which will be in a Viewbox so the user can resize the display. < Window Title Photo Cooperative Checkout Height 600...

Compatibility Is Based on Policy

There may come a time when you will not be able to capture all the requirements of a service interaction via the Web Services Description Language (WSDL) alone. This is where policies come in. Policies allow you to separate the what from the how and the whom when it comes to a communicated message. If you have policy assertions, you need to make sure you are very explicit with respect to expectations and compatibility. Keep these points in mind Say what your service can do, not how it does it...

Where the Action Is

Before stepping through this example in detail, we need to focus on the XMLHttp object, as it is the core of AJAX's asynchronous client-side processing. When Default.aspx loads, the user is presented with a text box and a prompt to enter the last name to search for. The user enters a letter e.g., L and releases the key, and a keyup event is fired. The keyup event was registered in the declaration of the TextBox ID TextBox1 runat server gt The showHint referred to is a JavaScript function return...

Dock Panel

A key property of the DockPanel element is that you can dock its contents to specific edges of the panel, as illustrated in Example 3-2. Take special note of the DockPanel declaration in bold and its attribute LastChildFill True this ensures that the last child of the panel will fill whatever space is left. Title Programming .NET 3.5 Layout DockPanel gt lt DockPanel LastChildFill True gt lt TextBlock DockPanel.Dock Top I am the top lt TextBlock gt lt TextBlock DockPanel.Dock Bottom I am the...

Stepby Step Walkthrough

With an understanding of the XMLHttp object in hand, let's walk through this example step by step. A full understanding of it will serve as the foundation for all of the material to come. The user begins, as noted previously, by typing a letter into the text box displayed by Default.aspx. The onkeyup event handler is called, and it checks to make sure the string has at least one letter, obtains the XMLHttp object, and sets the URL with the query string. It then sets the event handler for...

Adding a Watermark

You can improve the user experience by not wasting screen real estate with the Label. Instead, you can add another nifty little widget called the TextBoxWatermarkExtender. Return to the design view, take out the Label, and click on the arrow to the right of the TextBox. Click Add Extender, as you did before, and choose TextBoxWatermarkExtender in the Extender wizard. Then go to the properties window and select the TextBox1_ TextBoxWatermarkExtender control. Set the WatermarkText property to...

Creating a WPF Client Application

Next, you're going to create a WPF Application called StockQuotes. Leaving the current Visual Studio application running so you don't lose the port YahooQuotes is currently running on , start a new instance of Visual Studio 2008 and select New Project from the File menu. In the ensuing dialog, choose WPF Application as the project type, and name the project StockQuotes. When you've done this, make sure the XAML listing for Window1.xaml reads like this lt Window Title Yahooy Quotes Height 350...

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...

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...

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...

Creating a Check Out 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...

Stack Panel and Dock Panel

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...

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...

Master Detail 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...

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 Pattern Publish and Subscribe

Patterns Publish Subcribe Uml

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...

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 Data Helper 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....

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 Adventure WorksLT 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...

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...

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

Sample Login Page Sharp

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...

Stack Panel

Wpf Flowdocumentreader Find

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

Visual Studio Erd Diagram

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...

Canvas and View Box

Wpf Viewbox Icons

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...