[My Blog] | [Code Projects Home] | [skmMenu] | [RssFeed]

RssFeed Demos

The following demos illustrate the use of the RssFeed control, an ASP.NET server control designed to display RSS feeds in an ASP.NET Web page.

[Simple Demo] | [Simple Demo with Styles] | [Template Demo] | [Template Demo with ItemCommand]

In addition to the demos on this page, also check out:

CodeOutput
Description:
Demonstration of the default behavior of RssFeed...

 

Declarative Syntax:
<skm:rssfeed id="jamesSimple" runat="server">
</skm:rssfeed>

 

Code-Behind Code:
private void Page_Load(object sender, System.EventArgs e)
{
  if (!Page.IsPostBack)
  {
     jamesSimple.DataSource = "http://dotavery.com/blog/Rss.aspx";
     jamesSimple.DataBind();
  }
}
[Back to Top...]
Infozerk Inc.: averyBlog
May Lounge Update5/2/2008 4:15 PM
New Lounge Front-end (now with ASP.NET MVC and NHaml)4/30/2008 7:26 PM
Graffiti.Redirect 0.24/29/2008 10:01 PM
Focusing on Focus4/21/2008 9:43 PM
Free hosting for user groups from Applied Innovations4/18/2008 9:53 AM
Lounge Updates4/3/2008 12:11 PM
Restarting VisualStudioHacks.com3/13/2008 9:09 PM
Announcing Graffiti.Redirect 0.13/12/2008 2:44 PM
Great Startup Advice3/9/2008 10:28 PM
The Danger of Lorem ipsum3/7/2008 11:52 AM
Description:
Demonstration of the default behavior of RssFeed. The appearance has been improved using styles...

 

Declarative Syntax:
<skm:rssfeed HorizontalAlign="center" width="80%" 
           id="jamesStylin" runat="server" 
           HeaderText="The Avery Blog" Font-Names="Verdana"
           Font-Size="10pt" CellPadding="4">
  <AlternatingItemStyle BackColor="#E0E0E0" />
  <HeaderStyle Font-Size="14pt" HorizontalAlign="right" 
          Font-Bold="True" ForeColor="White" 
          BackColor="#000040"></HeaderStyle>
</skm:rssfeed>

 

Code-Behind Code:
private void Page_Load(object sender, System.EventArgs e)
{
  if (!Page.IsPostBack)
  {
     jamesStylin.DataSource = "http://dotavery.com/blog/Rss.aspx";
     jamesStylin.DataBind();
  }
}
[Back to Top...]
The Avery Blog
May Lounge Update5/2/2008 4:15 PM
New Lounge Front-end (now with ASP.NET MVC and NHaml)4/30/2008 7:26 PM
Graffiti.Redirect 0.24/29/2008 10:01 PM
Focusing on Focus4/21/2008 9:43 PM
Free hosting for user groups from Applied Innovations4/18/2008 9:53 AM
Lounge Updates4/3/2008 12:11 PM
Restarting VisualStudioHacks.com3/13/2008 9:09 PM
Announcing Graffiti.Redirect 0.13/12/2008 2:44 PM
Great Startup Advice3/9/2008 10:28 PM
The Danger of Lorem ipsum3/7/2008 11:52 AM
Description:
This demonstration shows that templates can be used to provide a high degree of customization

 

Declarative Syntax:
<skm:rssfeed HorizontalAlign="center" width="80%" 
           id="scottguTemplate" runat="server" 
           Font-Names="Verdana" Font-Size="10pt" 
           CellPadding="4">
  <AlternatingItemStyle BackColor="#E0E0E0" />
  <HeaderStyle Font-Size="14pt" HorizontalAlign="right" 
          Font-Bold="True" ForeColor="White" 
          BackColor="#000040"></HeaderStyle>
  <ItemTemplate>
    <strong><asp:Hyperlink runat="server"
        NavigateUrl='<%# Container.DataItem.Link %>'
        Text='<%# Container.DataItem.Title %>'></asp:Hyperlink>
    </strong>
    <br />
    <i><%# Container.DataItem.PubDate %></i><br />
    <%# Container.DataItem.Description %>
  </ItemTemplate>
</skm:rssfeed>

 

Code-Behind Code:
private void Page_Load(object sender, System.EventArgs e)
{
  if (!Page.IsPostBack)
  {
     scottguTemplate.DataSource = "http://weblogs.asp.net/scottgu/Rss.aspx";
     scottguTemplate.DataBind();
  }
}
[Back to Top...]
ScottGu's Blog
Visual Studio 2008 and .NET Framework 3.5 Service Pack 1 Beta
5/12/2008 12:51:33 PM

Earlier today we shipped a public beta of our upcoming .NET 3.5 SP1 and VS 2008 SP1 releases.  These servicing updates provide a roll-up of bug fixes and performance improvements for issues reported since we released the products last November.  They also contain a number of feature additions and enhancements that make building .NET applications better (see below for details on some of them).

We plan to ship the final release of both .NET 3.5 SP1 and VS 2008 SP1 this summer as free updates.  You can download and install the beta here.

Important: SP1 Beta Installation Notes

The SP1 beta released today is still in beta form - so you should be careful about installing it on critical machines.  There are a few important SP1 Beta installation notes to be aware of:

1) If you are running Windows Vista you should make sure you have Vista SP1 installed before trying to install .NET 3.5 SP1 Beta.  There are some setup issues with .NET 3.5 SP1 when running on the Vista RTM release.  These issues will be fixed for the final .NET 3.5 SP1 release - until then please make sure to have Vista SP1 installed before trying to install .NET 3.5 SP1 beta.

2) If you have installed the VS 2008 Tools for Silverlight 2 Beta1 package on your machine, you must uninstall it - as well as uninstall the KB949325 update for VS 2008 - before installing VS 2008 SP1 Beta (otherwise you will get a setup failure).  You can find more details on the exact steps to follow here (note: you must uninstall two separate things).  It is fine to have the Silverlight 2 runtime on your machine with .NET 3.5 SP1 - the component that needs to be uninstalled is the VS 2008 Tools for Silverlight 2 package.  We will release an updated VS 2008 Tools for Silverlight package in a few weeks that works with the VS 2008 SP1 beta.

3) There is a change in behavior in the .NET 3.5 SP1 beta that causes a problem with the shipping versions of Expression Blend.  This behavior change is being reverted for the final .NET 3.5 SP1 release, at which time all versions of Blend will have no problems running.  Until then, you need to download this recently updated version of Blend 2.5 to work around this issue.

Improvements for Web Development

.NET 3.5 SP1 and VS 2008 SP1 contain a bunch of feature improvements targeted at web application development. 

The VS Web Dev Tools team has more details (including specific bug fix details) on some of the VS specific work here.  Below are more details on some of the work in the web-space:

ASP.NET Data Scaffolding Support (ASP.NET Dynamic Data)

.NET 3.5 SP1 adds support for a rich ASP.NET data "scaffolding" framework that enables you to quickly build functional data-driven web application. With the ASP.NET Dynamic Data feature you can automatically build web UI (with full CRUD - create, read, update, delete - support) against a variety of data object models (including LINQ to SQL, LINQ to Entities, REST Services, and any other ORM or object model with a dynamic data provider).

SP1 adds this new functionality to the existing GridView, ListView, DetailsView and FormView controls in ASP.NET, and enables smart validation and flexible data templating options.  It also delivers new smart filtering server controls, as well as adds support for automatically traversing primary-key/foreign-key relationships and displaying friendly foreign key names - all of which saves you from having to write a ton of code.

You can learn more more about this feature from Scott Hanselman's videos and tutorials here.

ASP.NET Routing Engine (System.Web.Routing)

.NET 3.5 SP1 includes a flexible new URL routing engine that allows you to map incoming URLs to route handlers.  It includes support for both parsing parameters from clean URLs (for example: /Products/Browse/Beverages), as well as support to dynamically calculate and generate new URLs from route registrations.

This new routing engine is used by both ASP.NET Dynamic Data as well as the new ASP.NET MVC framework.  It will support both WebForms and MVC based requests. 

ASP.NET AJAX Back/Forward Button History Support

.NET 3.5 SP1 adds new APIs to ASP.NET AJAX to allow you to better control the history list of a browser (enabling you to control the behavior of the back/forward button of the browser).

You can learn more about this feature in the article here and the screencast here.

ASP.NET AJAX Script Combining Support

.NET 3.5 SP1 introduces a new <CompositeScript> element on the <asp:ScriptManager> server control, which allows you to declaratively define multiple script references within it.  All the script references within the CompositeScript element are combined together on the server and served as a single script to the client, reducing the number of requests to the server and improving page load time for ASP.NET AJAX applications.

The script combining feature supports both path based scripts and assembly resource based scripts, and dynamically serves up the combined scripts using the ScriptResources.axd handler.

Visual Studio 2008 Performance Improvements HTML Designer and HTML Source Editor

In February we released a HotFix roll-up that included a number of performance improvements and bug fixes for the VS 2008 Web Designer.  VS 2008 SP1 includes all of these fixes, as well as a number of additional performance improvements.

Visual Studio 2008 JavaScript Script Formatting and Code Preferences

Visual Studio has for several releases supported rich source code formatting options for VB and C# (spacing, line breaks, brace positions, etc).

VS 2008 SP1 adds richer source code formatting support for JavaScript as well (both inline <script> blocks and .js files).  You can now set your Javascript coding preferences using the Tools->Options dialog:

These preferences will be automatically used as you type new Javascript code in the source editor.  You can also select existing code, right-click, and choose the "Format Selection" option to apply your style preferences to existing JavaScript code.  You can learn more about this new feature here.

Better Visual Studio Javascript Intellisense for Multiple Javascript/AJAX Frameworks

VS 2008 includes Javascript Intellisense support in source view.  The intellisense support with the initial VS 2008 release works well with vanilla JavaScript as well as code written using the ASP.NET AJAX JavaScript type patterns.  JavaScript is a very flexible language, though, and many JavaScript libraries use this flexibility to full advantage to implement their features - sometimes in ways that prevented the intellisense engine from providing completion support.

VS 2008 SP1 adds much better intellisense support for popular Javascript libraries (we specifically did work to support JQuery, Prototype, Scriptaculous, ExtJS, and other popular libraries).  You will get better default intellisense when you reference these libraries.  We are also looking at whether we can maintain additional intellisense hint files that you can download to get even better intellisense and documentation support for some of the more popular libraries.

Below is an example of using a JQuery startup function with the VS 2008 SP1 JavaScript intellisense engine:

Notice below how VS 2008 SP1 can now provide method argument completion even on chained JQuery selectors:

Visual Studio Refactoring Support for WCF Services in ASP.NET Projects

VS 2008 SP1 adds better refactoring support for WCF services included within both ASP.NET Web Site and ASP.NET Web Application Projects.

If you use the refactoring support to rename the class name, interface contract, or namespace of a WCF service, VS 2008 SP1 will now automatically fix up the web.config and SVC file references to it.

Visual Studio Support for Classic ASP Intellisense and Debugging

Previous versions of Visual Studio included support for intellisense and debugging within classic ASP (.asp) pages.  The file and project templates to create classic ASP pages/projects hasn't been in VS for a few releases, though, and with the initial VS 2008 we incorrectly assumed this meant that people weren't still using the classic ASP support.  We heard feedback after we shipped that indeed they were. 

With VS 2008 SP1 this support for classic ASP intellisense and debugging is back:

 

Visual Web Developer Express Edition support for Class Library and Web Application Projects

The Visual Web Developer 2008 Express edition (which is free) is being updated in SP1 to add support for both class library and ASP.NET Web Application project types.  Previous versions of Visual Web Developer Express only supported ASP.NET web-site projects.

Among other benefits, the support of class library and web application projects will enable ASP.NET MVC and Silverlight projects to be built with the free Visual Web Developer 2008 Express.  All of the above JavaScript, Dynamic Data, Classic ASP, and AJAX improvements work with Visual Web Developer Express as well.

Improvements for Client Development

.NET 3.5 SP1 and VS 2008 SP1 contain major performance, deployment, and feature improvements for building client applications. 

Tim Sneath has a great blog post that talks about some of the client improvements here.  Below are more details on them:

Application Startup and Working Set Performance Improvements

.NET 3.5 SP1 includes significant performance improvements to the CLR that enable much faster application startup times - in particular with "cold start" scenarios (where no .NET application is already running).  Much of these gains were achieved by changing the layout of blocks within CLR NGEN images, and by significantly optimizing disk IO access patterns.  We also made some nice optimizations to our JIT code generator that allow much better inlining of methods that utilize structs.

We are today measuring up to 40% faster application startup improvements for large .NET client applications with SP1 installed.  These optimizations also have the nice side-effect of improving ASP.NET application request per second throughput by up to 10% in some cases.

New .NET Framework Client Profile Setup Package

.NET 3.5 SP1 introduces a new setup package option for developers building .NET client applications called the ".NET Framework Client Profile".  This provides a new setup installer that enables a smaller, faster, and simpler installation experience for .NET client applications on machines that do not already have the .NET Framework installed.

The .NET Framework Client Profile setup contains just those assemblies and files in the .NET Framework that are typically used for client application scenarios.  For example: it includes Windows Forms, WPF, and WCF.  It does not include ASP.NET and those libraries and components used primarily for server scenarios.  We expect this setup package to be about 26MB in size, and it can be downloaded and installed much quicker than the full .NET Framework setup package.

The assemblies and APIs in the .NET Framework Client setup package are 100% identical to those in the full .NET Framework setup package (they are literally the same binaries).  This means that applications can target both the client profile and full profile of .NET 3.5 SP1 (no recompilation required).  All .NET applications that work using the .NET Client Profile setup automatically work with the full .NET Framework.

A developer can indicate that the client application they are building supports both the .NET Framework Client Profile and the full .NET Framework by pulling up the project properties page for a client application within VS 2008 SP1.  Within the project properties page they can select a new checkbox that indicates it only requires those assemblies included in the .NET Framework Client Profile:

VS 2008 will then ensure that the project can only reference those assemblies shipped in the client profile setup package (and it will generate a compile error if you try and use a type in an assembly not included in the client redist).  The compiled client application will then run on machines that have both the full .NET Framework installed, as well as machines that only have the .NET Framework Client Profile installed.

If you have a machine that only has the .NET Framework Client Profile installed, and you try and run a .NET application on it that did not mark itself as supporting the .NET Framework Client Profile, then the CLR will refuse to run the application - and will instead prompt the end-user to upgrade to the full .NET Framework package.  This ensures that applications always run correctly - and that developers do not need to worry about missing assembly exceptions at runtime if a user tries to run an application that requires the full .NET Framework on a machine that only has the .NET Framework Client Profile installed.

We believe that a large class of .NET client applications will be able to use this new .NET Client Profile setup to significantly speed up their installation, and enable a much more consumer friendly experience.

New .NET Framework Setup Bootstrapper for Client Applications

.NET 3.5 SP1 introduces a new "bootstrapper" component that you can use with client applications to help automate making sure that the right version of the .NET Framework is installed. 

The bootstrapper component can handle automatically downloading and installing either the .NET Framework Client Profile or the full .NET Framework Setup Package from the Internet if your machine doesn't have either of them installed.  The boostrapper can also automatically handle upgrading machines that have a previous version of the .NET Framework installed.  For example, if your machine already has .NET 3.0 installed, and your application requires .NET 3.5, the bootstrapper can optionally download just the update files needed to upgrade it to .NET 3.5 (and avoid having to download the full .NET Framework setup download).

The setup bootstrapper component can be used with both ClickOnce based setup packages, as well as with third party installer products (like Installshield).  The boostrapper optionally enables fully customized setup branding experiences (splash screens, custom setup wizard steps, etc) and should make it much easier to build optimized client setup experiences.

ClickOnce Client Application Deployment Improvements

.NET 3.5 SP1 includes several improvements for ClickOnce deployment of both Windows Forms and WPF applications.  Some of these improvements include:

  • Support for the .NET Framework Client Profile (all ClickOnce features are supported with it)
  • ClickOnce applications can now be programmatically installed through a ‘Setup.exe’ while displaying a customized, branded install UX
  • ClickOnce improvements for generating MSI + ClickOnce application packages
  • ClickOnce error dialog boxes now support links to application specific support sites on the Web
  • ClickOnce now has design-time support for setting up file associations
  • ClickOnce application publishers can now decide to opt out of signing and hashing the ClickOnce manifests as they see appropriate for their scenarios.
  • Enterprises can now choose to run only Clickonce Applications Authenticode signed by ‘Known Publishers’ and block anything else from running
  • FireFox browser extension to support Clickonce installations using FireFox browsers

Windows Forms Controls

SP1 adds several new Windows Forms controls - including new vector shape, Printing, and DataRepeater controls:

 

WPF Performance Improvements

.NET 3.5 SP1 includes several significant performance optimizations and improvements to WPF.  Some of the specific graphics improvements include:

  • Smoother animations
  • Hardware accelerated rendering of Blur and DropShadow Bitmap Effects
  • Text Rendering speed improvements - especially with VisualBrish and 3D scenes
  • 2D graphics improvements - especially with z-index scenarios
  • A new WriteableBitmap class that enables real-time and tear-free bitmap updates.  This enables custom "paint"-style applications, data visualizations, charts and graphs that optionally bypass the default WPF 2D graphics APIs.
  • Layered window performance improvements

SP1 also adds support for better data scalability in WPF.  The ListView, ListBox and TreeView controls now support "item container recycling" and "virtualization" support which allows you to easily achieve a 40% performance improvement with scrolling scenarios.  These controls also now optionally support a "deferred scrolling" feature which allows you to avoid scrolling in real time and instead wait until a user releases the scroll thumb (the default scrolling mode in Outlook). This can be useful when scrolling over very large data sets quickly. 

WPF Data Improvements

.NET 3.5 SP1 includes several data binding and editing improvements to WPF.  These include:

  • StringFormat support within {{ Binding }} expressions to enable easy formatting of bound values
  • New alternating rows support within controls derived from ItemsControl, which makes it easier to set alternating properties on rows (for example: alternating background colors)
  • Better handling and conversion support for null values in editable controls
  • Item-level validation that applies validation rules to an entire bound item
  • MultiSelector support to handle multi-selection and bulk editing scenarios
  • IEditableCollectionView support to interface data controls to data sources and enable editing/adding/removing items in a transactional way
  • Performance improvements when binding to IEnumerable data sources

WPF also now exposes hooks that enable developers to write custom panels w/ virtualized scrolling.  We'll be using this support together with the above data binding improvements to build the new WPF datagrid that will be shipping later this year.

WPF Extensible Shader Effects

.NET 3.5 SP1 adds support in WPF for a new shader effects architecture and API that allows extremely expressive visual effects to be created and applied to any control or element within WPF.  These shader effects support blending multiple input compositions together.  What makes them particularly powerful is that WPF executes effects (including custom effects you build yourself) using the GPU - giving you fully hardware accelerated graphics performance.  Like almost everything in WPF, you can also use WPF databinding and animation on the properties of an effect (allowing them to be fully integrated into an experience).

Applying an effect onto a Control is super easy - just set a Control's "Effect" property.  For example, to add a hardware accelerated drop-shadow effect on a button you can use the built-in <DropShadowEffect> on it via either code or XAML:

Which will cause the button to render like so:

Because Effects are extensible, developers can create their own custom Effect objects and apply them.  For example, a custom "DirectionalBlurEffect" could be created and added to a ListBox control to change its scroll appearance to use a blur effect if you rapidly scroll across it:

Keep an eye on Greg Schechter's blog to learn more about how the Effects architecture works and to learn how you can both create and apply new effects within your applications (his first set of posts are here). 

Note: In addition to introducing the new Shader Effects API, WPF in SP1 also has updated the existing Blur and DropShadow Bitmap effects already in WPF to be hardware accelerated.

WPF Interoperability with Direct3D

.NET 3.5 SP1 adds support to efficiently integrate Direct3D directly into WPF.  This gives you more direct access to the hardware and to take full advantage of the Direct3D API within WPF applications.  You will be able to treat Direct3D content just like an image within an application, as well as use Direct3D content as textures on WPF controls. 

For example, below are three samples from the Direct3D SDK:

We could either load them in as image surfaces within a WPF application, or map them as textures on WPF controls.  Below is an example of mapping them as textures onto cubes in a WPF 3D application:

Note: the Direct3D integration isn't today's SP1 beta release.  It will appear in the final SP1 release.

VS 2008 for WPF Improvements

VS 2008 SP1 includes several significant improvements for WPF projects and the WPF designer.  These include:

  • Several performance improvements
  • Events tab support within the property browser
  • Ability to sort properties alphabetically in the property browser
  • Margin snaplines which makes form layout much quicker
  • Better designer support for TabControl, Expander, and Grid
  • Code initiated refactoring now updates your XAML (including both control declarations and event declarations in XAML)
  • Go to Definition and Find All References now support things declared in XAML

The debugger has also been updated in SP1 so that runtime errors in XAML markup (for example: referencing styles, datasources and/or other objects that don't exist) will now be better identified within the debugger:

Data Development Improvements

.NET 3.5 SP1 and VS 2008 SP1 include a bunch of improvements for data development. Some of them include:

SQL 2008 Support

VS 2008 and .NET 3.5 are being updated to include support for the upcoming SQL 2008 release.  Visual Studio 2008 data designers, projects and wizards now fully supporting connecting and working against SQL 2008 databases. 

ADO.NET Entity Framework and LINQ to Entities:

.NET 3.5 SP1 includes the new ADO.NET Entity Framework, which allows developers to define a higher-level Entity Data Model over their relational data, and then program in terms of this model.  Concepts like inheritance, complex types and relationships (including M:M support) can be modeled using it.  VS 2008 SP1 now includes built-in designer support to help with this modeling:

The ADO.NET Entity Framework and the VS 2008 Entity Framework Designer both support a pluggable provider model that allows them to be used with any database (including Oracle, DB2, MySql, PostgreSQL, SQLite, VistaDB, Informix, Sybase, and others).

Developers can then use LINQ and LINQ to Entities to query, manipulate, and update these entity objects.

ADO.NET Data Services (formerly code-named "Astoria")

.NET 3.5 SP1 includes a flexible framework that enables the creation of REST-based data services.  Formerly code-named "Astoria", the ADO.NET Data Services framework provides support for publishing data through a standard REST URI syntax and using standard HTTP verbs to operate on the data resources.  Developers can easily expose data models created using the ADO.NET Entity Framework, and/or use a pluggable provider model to expose other data models.

In addition to publishing data sources, the framework also adds a client API for working with remote REST services.  Included with this client API is a LINQ library that allows the remote query of REST services.

WCF Development Improvements

.NET 3.5 SP1 and VS 2008 SP1 include several enhancements for WCF development.  Some of these include:

  • Significant scalability improvements (5-10x) in Web-hosted application scenarios
  • Support for using ADO.NET Entity Framework entities in WCF contracts
  • API usability improvements with DataContract Serializers, and with the UriTemplate and WCF web programming models
  • Enhanced TestClient support within VS 2008 SP1
  • New Hosting Wizard in VS 2008 SP1 for WCF Service Projects
  • Improved debugging support in partial trust scenarios

VB and C# Improvements

The VB and C# teams have also added some nice improvements to VS 2008 SP1:

Visual Basic

You can now add "XML to Schema" items to Visual Basic projects.  On adding these project items a wizard will open that allows you to create a XSD schema set from a variety of XML sources.  This schema set is then added to the project and it enables VB XML intellisense. This support was previously available as a web download - you can learn more about it here.

A XSD browser is also now included with VS 2008 SP1 and allows you to browse XSD schema sets.  With the final SP1 release, developers will be able to right-click on XML element names (either in XML properties or XML literals) in the VB code editor and select “Go To XML Schema Definition” - this will open the XSD browser and display the schema set (and select the current element) for the VB project.

C#

The C# code editor now identifies and displays red squiggle errors for many semantic code issues that previously required an explicit compilation to identify.  For example, if you try to declare and use an unknown type in the C# code-editor today you won't see a compile error until you do a build.  Now with SP1 you'll see live red squiggle errors immediately (no explicit compile required):

The debugger in VS 2008 SP1 has also been improved to provide more debugging support for evaluating LINQ expressions and viewing results at debug time:

LINQ enabled data sources now have a "Results View" node show up within the debugger watch window.  Expanding this node will evaluate a LINQ expression and allow you to examine the materialized objects it returns:

Team Foundation Server Improvements

TFS 2008 SP1 includes a ton of improvements.  Please read Brian Harry's Team Foundation Server 2008 SP1 Preview blog post for more details.

Summary

.NET 3.5 SP1 and VS 2008 SP1 provide a bunch of bug fixes, performance improvements, and additional feature enhancements that make building all types of .NET applications better.  It will be a fully compatible service pack release. 

We plan to ship the final release of both .NET 3.5 SP1 and VS 2008 SP1 this summer as free updates.  You can download and use the beta now here.

Hope this helps,

Scott

Professional ASP.NET 3.5 Book (only $16 on Amazon for a short time)
5/6/2008 4:38:26 AM

One of the things I like to track are book sales on Amazon.com, which provides a useful data point to monitor what developers are interested in on any given day.  I use the www.TitleZ.com site (which is built using ASP.NET) to track specific titles I want to watch - it then generates a report showing real-time Amazon sales ranking data, as well as 7 day, 30 day and 90 day sales ranking averages.

This morning I pulled up my report and saw the usual books near the top of my list, and was about to navigate away when I noticed the eye-popping amazon ranking of the top book -"Professional ASP.NET 3.5: In C# and VB" by Bill Evjen, Scott Hanselman and Devin Rader.  Its Amazon sales rank was a stunning #95 (of all books on Amazon), which meant it was outselling even Harry Potter (which is pretty much unheard of for any technology book).

It turns out that Amazon is holding a special price promotion for a short time on a few books - and this was one that was selected.  Instead of the usual $54 price, you can buy it for a short time for a ridiculous $16.49.  I'm not sure how long this promotion will last - but if you are looking for a great ASP.NET 3.5 book this might be something you might want to take advantage of:

The book is a great ASP.NET 3.5 book and an excellent end to end resource.  It has been on the best seller list for programming books since it came out in March (usually in the top 5 of all programming titles), and has received glowing reviews (I posted a review of it on Amazon a few weeks ago and gave it 5 stars).

If you are in the market for a good ASP.NET book, you might want to consider taking Amazon up on this offer before it closes (and apologies in advance if the price changes before you read this).

Hope this helps,

Scott

P.S. If you are looking for other good .NET 3.5 and VS 2008 books - I also recommend: C# 3.0 In a Nutshell, LINQ in Action, and Pro LINQ: Language Integrated Query in C# 2008 (all of which average a 5 star rating on Amazon).

April 28th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Silverlight
4/29/2008 1:35:13 AM

Here is the latest in my link-listing series.  Also check out my ASP.NET Tips, Tricks and Tutorials page and Silverlight Tutorials page for links to popular articles I've done myself in the past.

ASP.NET

  • Displaying the Number of Active Users on an ASP.NET Site: Scott Mitchell continues his excellent series on ASP.NET's membership, roles, and profile support.  In this article he discusses how to use ASP.NET's Membership features to estimate and display the number of active users currently visiting a site.

  • ASP.NET Dynamic Data Update: The ASP.NET team last week released an update of the new ASP.NET Dynamic Data feature.  This update adds several new features including cleaner URL support using the same URL routing feature that ASP.NET MVC uses, as well as better confirmation, foreign-key, and template support. 

ASP.NET AJAX

  • ASP.NET AJAX UI Templates: Nikhil Kothari from the ASP.NET team has a cool post that shows off a prototype he has been working on that enables clean client-side AJAX templating of UI. 

ASP.NET MVC

  • Inversion of Control, ASP.NET MVC and Unit Testing: Fredrik Kalseth has a cool article that talks about the concepts behind inversion of control (IOC) and how you can use this with ASP.NET MVC to better isolate dependencies and enable better unit testing of your code.

Silverlight

  • Silverlight - the Song: Spike Xavier and Dan Wahlin have posted another of their unique and special songs. :-)

Hope this helps,

Scott

Slides from my ASP.NET Connections Orlando Talks
4/28/2008 12:51:55 AM

Last week I presented at the ASP.NET Connections Conference in Orlando.  I gave a general session talk on Monday, and then two breakout talks later that day.  You can download my slides+samples below:

General Session

The slides for my keynote can be downloaded here

In the talk I demonstrated how to debug the .NET Framework source code.  You can learn how to set this up with VS 2008 here

I also demonstrated building a site using the new ASP.NET Dynamic Data support - which you can learn more about here.  I also demonstrated using the new ASP.NET MVC Framework - which you can learn more about here.

I also showed off the new Hard Rock Memorabilia site built with Silverlight 2.  You can try out the Hard Rock application yourself here.  You can learn more about Silverlight from my links page here.

Building .NET Applications with Silverlight

The slides + demos for Silverlight breakout talk can be downloaded here.

You can learn more about Silverlight from my links page here.  In particular, I recommend reading my tutorial posts here and here.

ASP.NET MVC

The slides + demos for my ASP.NET MVC talk can be downloaded here.

You can learn more about the latest ASP.NET MVC source refresh here.  Stephen Walther also just posted a really good set of slides + demos from his post conference tutorial on ASP.NET MVC here.

Hope this helps,

Scott

ASP.NET MVC Source Refresh Preview
4/17/2008 12:56:47 AM

We recently opened up a new ASP.NET CodePlex Project that we will be using to provide previews (with buildable source code) for several upcoming ASP.NET features and releases.

Last month we used it to publish the first drop of the ASP.NET MVC source code.  This first drop included the source for the ASP.NET MVC Preview 2 release that we shipped at MIX, along with Visual Studio project files to enable you to patch and build it yourself.

A few hours ago we published a refresh of the ASP.NET MVC source code on the site.  This source refresh is not an official new ASP.NET MVC preview release - instead it is an interim drop that provides a look at the current state of the source tree.  We will ship the official "ASP.NET MVC Preview 3" release in a few weeks after we finish up some more work (more features and tweaks to existing ones, better VS tool integration, VS express edition support, documentation, etc).  If you are someone who wants a hassle-free installation of ASP.NET MVC to use that ships with documentation and full tool support you'll probably want to wait for this official preview release.  If you are someone who wants a chance to see an early "preview of the preview" and have the opportunity to start using and giving feedback on some of the features immediately, today's source refresh is probably interesting to look at.

Improvements with this ASP.NET MVC Source Refresh

This week's update (which you can download here) includes a number of improvements to ASP.NET MVC.  Some of these include:

  • In addition to posting the source code for the ASP.NET MVC framework, we are also posting the source code for the unit tests that we use to test it.  These tests are implemented using MSTest and the open source Moq mocking framework.  A VS 2008 project file for the unit tests is included to make it easy to build and run them locally within your VS 2008 IDE.

  • Significantly easier support for testing Controller classes.  You can now unit test common Controller scenarios without having to mock any objects (more details on how this works below).

  • Several nice feature additions and usability improvements to the URL routing system (more details below).

Creating a New ASP.NET MVC Project

You can build your own copy of the ASP.NET MVC assemblies by downloading the MVC source and compiling it locally, or alternatively you can download a VS Template package to get a pre-built version of them along with a Visual Studio project template that you can use to quickly build a new ASP.NET MVC Project that uses the latest bits.

After you install the ASP.NET MVC source refresh .VSI template, a new "ASP.NET MVC Application" project template will show up under the "My Templates" section of your "New Project" dialog:

This new "My Templates" version of the MVC project template lives side-by-side with the previous ASP.NET MVC Preview 2 release (which you can see above it in the main project templates section of the dialog).  This allows you to safely create new projects and and use both the latest source version and the last official preview version on the same machine.

When you create a new project using this updated ASP.NET MVC Project template you'll by default get a project that looks like below:

This new project solution contains one Controller ("HomeController") under the "\Controllers" directory and two View templates ("About" and "Index") under the "\Views\Home" sub-directory.  Both view templates are based on a common master page for the site ("Site.master"), all of whose styles are defined within a "Site.css" file under the "\Content" directory.

When you run the application the built-in web-server will automatically start up and you'll see the site's "Home" content:

Clicking the "About us" tab will then display the "About" content:

The "HomeController" class in the project is responsible for handling both of the URLs above and has two action methods like below:

The default "Site.master" template looks for a "Title" value in the ViewData collection and uses it to render the <title> element of the HTML page.  The default "Index" view template looks for a "Message" value and uses it to render the home page's welcome message.  You can obviously go in and customize these files however you want.

Controller Changes with this ASP.NET MVC Drop

If you were reading the above code closely you might have noticed a few changes with how Controller classes are by default implemented using this new ASP.NET MVC source refresh drop. 

With the ASP.NET MVC Preview 2 release the above HomeController action methods would have instead been implemented like below:

The MVC feature team is experimenting with a few ideas in this week's drop and are trying out some new ideas:

  1. Action methods on Controllers now by default return an "ActionResult" object (instead of void).  This ActionResult object indicates the result from an action (a view to render, a URL to redirect to, another action/route to execute, etc). 

  2. The RenderView(), RedirectToAction(), and Redirect() helper methods on the Controller base class now return typed ActionResult objects (which you can further manipulate or return back from action methods).

  3. The RenderView() helper method can now be called without having to explicitly pass in the name of the view template to render.  When you omit the template name the RenderView() method will by default use the name of the action method as the name of the view template to render.  So calling "RenderView()" with no parameters inside the "About()" action method is now the same as explicitly writing "RenderView('About')".

It is pretty easy to update existing Controller classes built with Preview 2 to use this new pattern (just change void to ActionResult and add a return statement in front of any RenderView or RedirectToAction helper method calls).

Returning ActionResult Objects from Action Methods

So why change Controller action methods to return ActionResult objects by default instead of returning void?  A number of other popular Web-MVC frameworks use the return object approach (including Django, Tapestry and others), and we found for ASP.NET MVC that it brought a few nice benefits:

  1. It enables much cleaner and easier unit testing support for Controllers.  You no longer have to mock out methods on the Response object or ViewEngine objects in order to unit test the response behavior of action methods.  Instead, you can simply assert conditions using the ActionResult object returned from calling the Action method within your unit test (see next section below).

  2. It can make Controller logic flow intentions a little clearer and more explicit in scenarios where there might be two different outcomes depending on some condition (for example: redirect if condition A is true, otherwise render a view template it is false).  This can make non-trivial controller action method code easier to read and follow.

  3. It enables some nice composition scenarios where a FilterActionAttribute can take the result of an action method and modify/transform it before executing it.  For example: a "Browse" action on a ProductCatalog controller might return an RenderActionResult that indicates it wants to render a "List" view of products.  A FilterActionAttribute declaratively set on the controller class could then have a chance to customize the specific "List" view template rendered to be either List-html.aspx or List-xml.aspx depending on the preferred MIME type of the client.  Multiple FilterActionAttributes can also optionally be chained together to flow the results from one to another.

  4. It provides a nice extensibility mechanism for people (including ourselves) to add additional features in the future.  New ActionResult types can be easily created by sub-classing the ActionResult base class and overriding the "ExecuteResult" method.  It would be easy to create a "RenderFile()" helper method, for example, that a developer writing an action could call to return a new "FileActionResult" object.

  5. It will enable some nice Asynchronous execution scenarios in the future.  Action methods will be able to return an AsyncActionResult object which indicates that they are waiting on a network operation and want to yield back the worker thread so that ASP.NET can use it to execute another request until the network call completes.  This will enable developers to avoid blocking threads on a server, and support very efficient and scalable code.

One of the goals with this interim preview is to give people a chance to play around with this new approach and do real-world app-building and learning with it.

We will also post an alternative Controller base class sample that you can use if you still prefer the previous "void" action return approach.  We deliberately didn't include this alternative Controller base class in this source refresh drop, though, because we want to encourage folks to give the "ActionResult" return approach a try and send us their app-building feedback on it.

How To Unit Test Controller Action Methods

I mentioned above that the new ActionResult approach can make unit testing controllers much easier (and avoid the need to use mocking for common scenarios).  Let's walk through an example of this in action.

Consider the simple NumberController class below:

This Controller class has an "IsEvenNumber" action method that takes a number as a URL argument.  The IsEvenNumber action method first checks whether the number is negative - in which case it redirects the user to an error page.  If it is a positive number it determines whether the number is even or odd, and renders a view template that displays an appropriate message:

Writing unit tests for our "IsEvenNumber" action method is pretty easy thanks to the new ActionResult approach.

Below is an example unit test that verifies that the correct Http redirect occurs when a negative number is supplied (for example: /Number/IsEvenNumber/-1):

Notice above how we did not need to mock any objects to test our action method.  Instead we simply instantiated the NumberController class and called the action method directly (passing in a negative number) and assigned the return value to a local "result" variable.  I used the C# "as type" syntax above to cast the "result" variable as a strongly typed "HttpRedirectResult" type.

What is nice about the C# "as" keyword is that it will assign the value as null instead of throwing an exception if the cast fails (for example: if the action method returned a RenderViewResult instead).  This means I can easily add an assertion check in my test to verify that the result is not null in order to verify that an Http redirect happened.  I can then add a second assertion check to verify that the correct redirect URL was specified.

Testing the scenarios where non-zero numbers are passed in is also easy.  To do this we'll create two test methods - one testing even numbers and one testing odd numbers.  In both tests we'll assert that a RenderViewResult was returned, and then verify that the correct "Message" string was passed within the ViewData associated with the view:

We can then right click on our NumberControllerTest class inside VS 2008 and choose the "Run Tests" menu item:

This will execute our three unit tests in-memory (no web-server required) and report back on whether our NumberController.IsEvenNumber() action method is performing the right behavior:

Note: with this week's source drop you still need to use mocking to test the TempData property on Controllers.  Our plan is to not require mocking to test this with the ASP.NET MVC Preview 3 drop in a few weeks.

MapRoute Helper Method

URL routing rules within ASP.NET MVC applications are typically declared within the "RegisterRoutes" method of the Global.asax class.

With ASP.NET MVC Previews 1 and 2 routes were added to the routes collection by instantiating a Route object directly, wiring it up to a MvcRouteHandler class, and then by setting the appropriate properties on it to declare the route rules:

The above code will continue to work going forward.  However, you can also now take advantage of the new "MapRoute" helper method which provides a much simpler syntax to-do the same thing.  Below is the convention-based URL route configured by default when you create a new ASP.NET MVC project (which replaces the code above):

The MapRoute() helper method is overloaded and takes two, three or four parameters (route name, URL syntax, URL parameter default, and URL parameter regular expression constraints). 

You can call MapRoute() as many times as you want to register multiple named routes in the system.  For example, in addition to the default convention rule, we could add a "Products-Browse" named routing rule like below:

We can then refer to this "Products-Browse" rule explicitly within our Controllers and Views when we want to generate a URL to it.  For example, we could use the Html.RouteLink view helper to indicate that we want to link to our "Products-Browse" route and pass it a "Food" category parameter using code in our view template like below:

This view helper would then access the routing system and output an appropriate HTML hyperlink URL like below (note: how it did automatic parameter substitution of the category parameter into the URL using the route rule):

Note: with this week's source drop you need to pass-in the controller and action parameters (in addition to the Category param) to the Html.RouteLink() helper to resolve the correct route URL to generate.  The ASP.NET MVC Preview 3 drop in a few weeks will not require this, and allow you to use the Html.RouteLink call exactly as I've written it above to resolve the route.

Other URL Route Mapping Features

This week's MVC source drop also supports a bunch of new URL route mapping features.  You can now include "-", ".", ";" or any other characters you want as part of your route rules.

For example, using a "-" separator you can now parse the language and locale values from your URLs separately using a rule like below:

This would pass appropriate "language", "locale", and "category" parameters to the ProductsController.Browse action method when invoked:

URL Route Rule Example URL Parameters Passed to Action method
{language}-{locale}/products/browse/{category} /en-us/products/browse/food language=en, locale=us, category=food
  /en-uk/products/browse/food language=en, locale=uk, category=food

Or you can use the "." file extension type at the end of a URL to determine whether to render back the result in either a XML or HTML format:

This would pass both "category" and a "format" parameters to the ProductsController.Browse action method when invoked:

URL Route Rule Example URL Parameters Passed to Action method
products/browse/{category}.{format} /products/browse/food.xml category=food, format=xml
  /products/browse/food.html category=food, format=html

ASP.NET MVC Preview 2 introduced wildcard route rules.  For example, you can indicate in a rule to pass all remaining URI content on as a named parameter to an action method:

This would pass a "contentUrl" parameter to the WikiController.DisplayPage action method when invoked:

URL Route Rule Example URL Parameters Passed to Action method
Wiki/Pages/{*contentUrl} /Wiki/Pages/People/Scott contentUrl="People/Scott"
  /Wiki/Pages/Countries/UK contentUrl="Countries/UK"

These wildcard routes continue to work fine with this week's preview - and are very useful to look at if you are building a blogging, wiki, cms or other content based system.

Note that in addition to using the new routing system for ASP.NET MVC scenarios, we are also now using the same routing system within ASP.NET Dynamic Data (which uses ASP.NET Web Forms).

Summary

Hopefully the above post provides a quick update on some of the new features and changes exposed with this week's ASP.NET MVC source update drop. 

You can download it here if you want to start using it immediately.  Alternatively, you can wait a few weeks for the official ASP.NET MVC Preview 3 drop - which will have some more features (and incorporate feedback people provide on this week's drop), deliver a more seamless installer, provide nice VS integration, and deliver up to date documentation.

For any questions/issues with this week's drop of ASP.NET MVC, make sure to also check out the ASP.NET MVC forum on www.asp.net.

Hope this helps,

Scott

April 11th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight
4/11/2008 3:04:22 AM

Here is the latest in my link-listing series.  Also check out my ASP.NET Tips, Tricks and Tutorials page and Silverlight Tutorials page for links to popular articles I've done myself in the past.

ASP.NET

  • 50 Useful CSS Tips and Tricks: A useful page that provides a nice listing of various CSS tips, tricks and tools you can use for common web scenarios.

ASP.NET AJAX

  • Accessible UpdatePanel: Bertrand Le Roy from the ASP.NET team has an article that describes how to make the ASP.NET AJAX's UpdatePanel control accessible for screen-readers.

  • Building ASP.NET AJAX Components: Mike Ormond has written an excellent 8-part series that covers building re-usable ASP.NET AJAX components that work on both the client and server.

ASP.NET MVC

  • ASP.NET MVC: Membership Starter Kit: Troy Goode has a built an awesome membership starter kit for ASP.NET MVC that provides registration and login pages for users to authenticate on your site, as well as a set of administration functionality that allows admins to create/manage users and roles.  Download it here.

  • How to Enable Pretty URLs with ASP.NET MVC and IIS6: James Geurts posts a useful article that describes how to enable extension-less URLs with ASP.NET MVC on IIS6 (note: you do not need to configure anything special with ASP.NET MVC on IIS7 to enable extension-less URL support).

Visual Studio

Silverlight

  • Dave Campbell's Excellent Silverlight Link Series: Dave Campbell posts a regular series of links to new Silverlight articles and content on the web.  I highly recommend subscribing to his blog if you want to stay current with all the latest Silverlight articles and posts.

  • Silverlight 2 Map / DataGrid Tutorial: Jason Zander has a great two-part Silverlight tutorial that demonstrates how to build a nice data-driven application that integrates a map control with a datagrid to filter and analyze data.

Hope this helps,

Scott

ASP.NET Dynamic Data Preview Available
4/10/2008 3:44:47 AM

A few months ago we released an ASP.NET 3.5 Extensions Preview that contained a bunch of new features that will be shipping later this year (including ASP.NET AJAX Improvements, ASP.NET MVC, ASP.NET Silverlight Support, and ASP.NET Dynamic Data).

The ASP.NET Dynamic Data support within that preview provided a first look at a cool new feature that enables you to quickly build data driven web-sites that work against a LINQ to SQL or LINQ to Entities object model.  ASP.NET Dynamic Data allows you to automatically render fully functional data entry and reporting pages that are dynamically constructed from your ORM data model meta-data.  In addition to supporting a dynamic rendering mode, it also allows you to optionally override and customize any of the view templates using any HTML or code you want (given you full control of the experience).

ASP.NET Dynamic Data Preview

Today we released an updated ASP.NET Dynamic Data Preview.  You can learn more about it and download it here.

This new dynamic data preview now works with the standard built-in ASP.NET data controls (GridView, ListView, FormView, DetailsView, etc).  The dynamic data support enables these controls to automatically handle foreign-key relationships.  For example, on a gridview you'll now get automatic friendly name display of foreign key column values and automatic drop-down list selection support of these values when in edit mode:

The new dynamic data support also provides automatic UI validation support (both client-side and server-side) based on the constraints you set on your data model classes.  For example, if a column in the database is limited to 50 characters in size, and is marked as non-nullable, appropriate UI control validators will automatically be applied by ASP.NET dynamic data to enforce this constraint in the UI pages as well.  If you change the constraints within your LINQ to SQL or LINQ to Entities data model classes, the UI will automatically pick up these changes and enforce the new constraints on the next web request.

In addition to standard data model metadata, you can also declare custom metadata to further control validation and the default display of UI of objects. 

You will be able to use all of the above features with both LINQ to SQL and LINQ to Entities.

Visual Studio Dynamic Data Project Wizard

In addition to the core ASP.NET dynamic data runtime support, the VS web tools team today also shipped a first preview of a new dynamic data project wizard that enables you to quickly get a data driven web-site started.  The wizard allows you to select a database, and then the tables, views and sprocs within it that you want to build a LINQ to SQL data model around:

After creating a data model, the wizard allows you to easily choose dynamic data driven template pages to build UI around it:

You can then choose what type of inserting/editing/updating UI is supported on each page:

And when you click finish it will setup a project with your data model classes and data UI pages setup to run.  You can learn more about the wizard and watch it in action in a blog post and screencast here.

How to Get Started

You can learn more about this new dynamic data preview and download and run it locally here.

You can watch David Ebbo's dynamic data presentation at MIX 08 to learn more about how it works.  Also check out Scott Hunter's screen-cast here, and Brad Millington's screen cast here.  David also has a post here that talks about the changes made between the December preview and today's preview release.

You can ask questions and submit feedback via the www.asp.net forums here.

Hope this helps,

Scott

Tip/Trick: Creating and Using Silverlight and WPF User Controls
4/4/2008 4:37:20 AM

One of the fundamental design goals of Silverlight and WPF is to enable developers to be able to easily encapsulate UI functionality into re-usable controls.

You can implement new custom controls by deriving a class from one of the existing Control classes (either a Control base class or from a control like TextBox, Button, etc).  Alternatively you can create re-usable User Controls - which make it easy to use a XAML markup file to compose a control's UI (and which makes them super easy to build).

In Part 6 of my Digg.com tutorial blog series I showed how to create a new user control using VS 2008's "Add New Item" project item dialog and by then defining UI within it.  This approach works great when you know up front that you want to encapsulate UI in a user control.  You can also use the same technique with Expression Blend.

Taking Existing UI and Encapsulating it as a User Control

Sometimes you don't always know you want to encapsulate some UI functionality as a re-usable user control until after you've already started defining it on a parent page or control.

For example, we might be working on a form where we want to enable a user to enter shipping and billing information.  We might begin by creating some UI to encapsulate the address information.  To-do this we could add a <border> control to the page, nest a grid layout panel inside it (with 2 columns and 4 rows), and then place labels and textbox controls within it:

After carefully laying it all out, we might realize "hey - we are going to use the exact same UI for the billing address as well, maybe we should create a re-usable address user control so that we can avoid repeating ourselves". 

We could use the "add new item" project template approach to create a blank new user control and then copy/paste the above UI contents into it. 

An even faster trick that we can use within Blend, though, is to just select the controls we want to encapsulate as a user control in the designer, and then "right click" and choose the "Make Control" menu option:

When we select the "Make Control" menu item, Blend will prompt us for the name of a new user control to create:

We'll name it "AddressUserControl" and hit ok. This will cause Blend to create a new user control that contains the content we selected:

When we do a re-build of the project and go back to the original page, we'll see the same UI as before - except that the address UI is now encapsulated inside the AddressUserControl:

We could name this first AddressUserControl "ShippingAddress" and then add a second instance of the user control to the page to record the billing address (we'll name this second control instance "BillingAddress"):

And now if we want to change the look of our addresses, we can do it in a single place and have it apply for both the shipping and billing information.

Data Binding Address Objects to our AddressUserControl

Now that we have some user controls that encapsulate our Address UI, let's create an Address data model class that we can use to bind them against.  We'll define the class like below (taking advantage of the new automatic properties language feature):

Within the code-behind file of our Page.xaml file we can then instantiate two instances of our Address object - one for the shipping address and one for the billing address (for the purposes of this sample we'll populate them with dummy data).  We'll then programmatically bind the Address objects to our AddressUserControls on the page.  We'll do that by setting the "DataContext" property on each user control to the appropriate shipping or billing address data model instance:

Our last step will be to declaratively add {Binding} statements within our AddressUserControl.xaml file that will setup two-way databinding relationships between the "Text" properties of the TextBox controls within the user control and the properties on the Address data model object that we attached to the user control:

When we press F5 to run the application we'll now get automatic data-binding of the Address data model objects with our AddressUserControls:

Because we setup the {Binding} declarations to be "Mode=TwoWay", changes users make in the textboxes will automatically get pushed back to the Address data model objects (no code required for this to happen). 

For example, we could change our original shipping address in the browser to instead go to Disneyland:

If we wire-up a debugger breakpoint on the "Click" event handler of the "Save" button (and then click the button), we can see how the above TextBox changes are automatically reflected in our "_shippingAddress" data model object:

We could then implement the SaveBtn_Click event handler to persist the Shipping and Billing Address data model objects however we want - without ever having to manually retrieve or manipulate anything in the UI controls on the page.

This clean view/model separation that WPF and Silverlight supports makes it easy to later change the UI of the address user controls without having to update any of our code in the page.  It also makes it possible to more easily unit test the functionality (read my last post to learn more about Silverlight Unit Testing).

Summary

WPF and Silverlight make it easy to encapsulate UI functionality within controls, and the user control mechanism they support provides a really easy way to take advantage of this.  Combining user controls with binding enables some nice view/model separation scenarios that allow you to write very clean code when working with data.

You can download a completed version of the above sample here if you want to run it on your own machine. 

To learn even more about Silverlight and WPF, check out my Silverlight Tutorials and Links Page.  I also highly recommend Karen Corby's excellent MIX08 talk (which covers User Controls, Custom Controls, Styling, Control Templates and more), which you can watch online for free here.

Hope this helps,

Scott

Unit Testing with Silverlight
4/2/2008 5:01:42 AM

One of the important capabilities we shipped with the Beta1 release of Silverlight 2 was a unit test harness that enables you to perform both API-level and UI-level unit testing.  This testing harness is cross browser and cross platform, and can be used to quickly run and verify automated unit tests:

In addition to shipping this unit test harness for Silverlight, we also shipped the source to ~2,000 unit tests built with it that provide automated coverage for the Silverlight control source that we also shipped under a permissive license (you can take the control source, modify it, run the unit tests to verify the behavior, then re-ship the controls however you want).

Learning How to Unit Test Silverlight

Jeff Wilcox (who developed the Silverlight unit test framework and harness) has a great blog post that talks about how to add a Silverlight Unit Test project to a solution here. You can download the chat application that he shows testing from this expression blend blog post tutorial I did last month.  You can also watch this cool video post that Jeff created where he walks through the unit test framework and test cases we've shipped.

As Jeff shows in his post, you can now add a "Silverlight Test Project" to your Visual Studio solution which encapsulates unit tests for an application you are working on:

You can then add unit test classes to the test project that test APIs or simulate UI action within the Silverlight controls (simulate button clicks, etc).

You can then run the test project and execute the tests within it to verify and report their status.

Jeff's test framework automatically provides a browser based test harness and reporting system (which means you can run it on any browser/OS combination that Silverlight runs on):

Jeff's test framework supports quickly re-setting controls after each test (and avoids needing to re-launch a new browser instance for each test cases - which makes it really fast).

You can quickly rip through hundreds or thousands of automated tests in seconds:

Green results mean the tests passed.  Red results flag that a test case failed and log the assertion failure and/or runtime exceptions that occurred.

Summary

If you've ever struggled to try and come up with a strategy for doing automated unit testing or TDD with AJAX applications, I think you'll find Silverlight provides some much nicer test options.  Using Visual Studio you can also separate your tests into a separate project in your solution, and you do not need to embed the tests within your Silverlight application in order for them to run.

In addition to supporting the above unit test harness and framework, we are also going to support UI automation APIs with the final release of Silverlight 2.  These will enable accessibility scenarios (allowing screen readers to work with Silverlight and enable Section 508 compliance of Silverlight applications).  These UI automation APIs will also enable UI testing scenarios where you can build end to end browser UI automation that simulates real mouse and keyboard interactions and enables automated end to end experience testing.  The combination should enable you to build much more solid and maintainable RIA solutions.

Hope this helps,

Scott

P.S. For more tutorial posts and links on Silverlight 2, check out my new "Silverlight Tips, Tricks, Tutorials and Links" page.

March 28th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight, .NET
3/28/2008 4:08:18 AM

Here is the latest in my link-listing series.  Also check out my ASP.NET Tips, Tricks and Tutorials page for links to popular articles I've done myself in the past.

ASP.NET

ASP.NET AJAX

ASP.NET MVC

  • Kigg - Building a Digg Clone with ASP.NET MVC: Kazi Manzur Rashid published an excellent Digg-clone sample built with ASP.NET MVC last February.  He recently updated the code to work with ASP.NET MVC Preview 2 (full details here).  You can download the latest version of his source code here.

  • Testing with the ASP.NET MVC Framework: Simone Chiaretta has a great article that discusses how to test controllers using ASP.NET MVC Preview 2.  Note: the next ASP.NET MVC preview release will include a number of refactorings that will simplify controller testing considerably (and avoid the need to mock anything for common scenarios).

Visual Studio

  • VS 2008 Web Deployment Hot-Fix Roll-Up Now Available for non-English Languages: Last month we shipped a hot-fix release that fixes a number of bugs, adds a few features, and improves performance for web development scenarios in VS 2008 and Visual Web Developer 2008 Express.  Last month's release only worked with the English-language VS 2008 products.  Yesterday we shipped an update that now works for all VS 2008 languages except Portuguese and Russian (which are still to come in the future). 

  • Hotfix Available for VB Performance Issue in VS 2008: The Visual Basic team recently released a hotfix as well that addresses a performance issue with large files that contain XML documentation.  Read this post to learn more about how to download it if you are running into this issue.

Silverlight

  • Using Silverlight 2's DataGrid with WCF + LINQ to SQL: This 15 minute video blog demonstrates how to build a LINQ to SQL object model on the server and publish it using WCF.  It then demonstrates how to build a Silverlight client that uses the new Silverlight DataGrid control, and which calls the WCF service to retrieve the LINQ to SQL data to populate it with.

  • Simple Editing of Web Service Data in a DataGrid: Mike Taulty has a nice blog post that shows how to create a WCF service on the server, and then use it from a Silverlight 2 client to retrieve data, bind it to a DataGrid, allow users to update rows, add/delete rows, and then save it back to the server using Silverlight 2 Beta1.

  • Sorting with Silverlight 2's DataGrid Control: The DataGrid control in Silverlight 2 Beta1 doesn't yet have built-in column sorting support (it is coming in Beta2).  That hasn't stopped Matt Berseth though!  In this post he shows how to implement sorting using a custom header column approach.  Also check out Matt's post here, which provides a DataGrid test page that shows off a number of the current DataGrid features.

  • Open Source Silverlight Charts with VisiFire: Silverlight doesn't yet have built-in charting controls.  The good news is that the folks at Webyog just released a really cool set of open source Silverlight charting controls (complete with animation support) that enable you to easily build great looking charts.  Their model makes it super easy to use the chart components within existing HTML or AJAX applications.

.NET

  • FormatWith and DateTime Extension Methods: James Newton-King and Fredrik Kalseth have some nice posts and samples that demonstrate how to use the new extension method feature in the VB and C# languages in VS 2008 to create some useful convenience libraries. 

Hope this helps,

Scott

New Log Reporting, Database Management, and other cool admin modules for IIS 7
3/26/2008 4:47:04 AM

One of the core priorities we focused on when building IIS 7 was to enable a rich .NET extensibility model that provides developers with the hooks to easily plug-in and extend the web server. 

These extensibility hooks are provided in the web-server pipeline (enabling scenarios like the new IIS7 Bit Rate Throttler), within the configuration system (enabling developers to create new web.config schema settings), within the health monitoring system (enabling developers to add custom trace events), and within the admin tool (enabling developers to plug-in new admin UI modules).

We added these extensibility hooks so that anyone can easily extend and enhance the web server using .NET.  We also selfishly wanted them so that we can ship regular feature packs that add additional features to the core web server.

IIS 7 Admin Pack Preview 1 Released

Last week the IIS team shipped the first technical preview of some really cool administration modules that I think web developers will find super useful.  This preview adds several new features to the IIS7 Admin Tool:

  • Database Manager: Built-in SQL Server database management, including the ability to create, delete, and edit tables and indexes, create/edit SPROCs and execute custom queries.  Because it is integrated in the IIS administration tool it all works over HTTP/SSL - which means you can use the module to remotely manage your hosted applications (even with low-cost shared hosting accounts), without having to expose your database directly on the Internet.

  • Log Reports: Built-in report visualization with charting support for log files data.  Full range selection and custom chart creation is supported, as well as the ability to print or save reports.  Like the database manager you can use this module remotely over HTTP/SSL - which means it works in remote shared hosting scenarios.

  • Configuration Editor: This is a power module that provides complete control over editing all web.config settings within the admin tool.  You can configure it to track the changes you make using the UI and have it auto-generate configuration change scripts that you can then save and tweak to re-run later in an automated way.

  • Request Filtering UI: This admin module provides more control over the new request filtering feature in IIS7.  Check out Carlos' blog post