About the Author

Adam joined InterKnowlogy in 2004 and oversees the Application Development Practice. He is an accomplished software developer, C# MVP, author, teacher and speaker with over twelve years of experience designing, developing and leading large-scale mission critical software projects. Adam is also very active in the development community where he is a member of Microsoft’s UI Frameworks Council, teaches classes at UCSD Extension, serves on the Board of Directors for the San Diego .NET Developers Group, and is a renowned speaker at user groups and conferences.

An End to Reflector as we know it?

I was totally bummed to get the following email from Lutz Roeder today. It seems that Reflector the tool I am come to love and cherish is now under the control of Redgate software. I hope they continue with the tradition that has made this application one of the must have tools for .NET developers.

Lutz email:

After more than eight years of working on .NET Reflector, I have decided it is time to move on and explore some new opportunities.

I have reached an agreement to have Red Gate Software continue the development of .NET Reflector. Red Gate has a lot of experience creating development tools for both .NET and SQL Server. They have the resources necessary to work on new features, and Reflector fits nicely with other .NET tools the company offers.

Red Gate will continue to provide the free community version and is looking for your feedback and ideas for future versions.

For news and updates on Reflector, sign up for the .NET Developer’s Newsletter from Red Gate. To find out more about the agreement, see the interview on Simple Talk.

Attached Events in Silverlight == false

As I am digging more and more into Silverlight I find more and more features I have come to love in WPF that are just not there. One feature is Attached Events. In WPF I can do something like this in XAML.

<StackPanel Height="25"  Orientation="Horizontal"  ButtonBase.Click="StackPanelCommon_Click">
    <Button Name="Yes" Margin="5,0,5,0" Content="Yes"/>
    <Button Name="No" Margin="5,0,5,0" Content="No"/>
    <Button Name="Cancel" Margin="5,0,5,0" Content="Cancel"/>
</StackPanel>

In this scenario the StackPanelCommon_Click handler will handle the click event for the Yes, No and Cancel buttons. Inside this handler I can add code to determine the particular button selected and implement logic accordingly (see below).

private void StackPanelCommon_Click(object sender, RoutedEventArgs e)
{
  Button button = e.Source as Button;
  if(button != null)
  {
    switch (button.Name)
    {
      case "Yes":
        //some logic goes here
        break;
      case "No":
        //some logic goes here
        break;
      case "Cancel":
        //some logic goes here
        break;
    }
  }
}

But when I try this in Silverlight I get the following error.

So what the heck is going on here? It turns out that UIElement does not support the AddHandler method which allows you to add handlers to the UIElement.

I hope in future versions Microsoft can add this into Silverlight to help promote more concise coding approaches since the alternative is similar to the old days gone by.

 

ASP.NET AJAX Roadmap and Client-Side Binding

Betrand Le Roy blogged about the released the Microsoft ASP.NET Ajax Road Map

which describes some of the new proposed features of ASP.NET AJAX. One of the topics in this document centered around working with data on the client which is something I have been anticipating for quite a while. Up until now working with data on the client has been a mixed bag of solutions that never seemed to completely gel (remember the xml-script stuff) and approaching the problem with UI Templates, bi-directional data binding and new “mixed mode” controls that work with data on both the client and the server seems like an approach that finally gels.

UI Templates

Templates have been around for quite a long time in ASP.NET and moving this concept to the client makes life much easier. I can remember building up HTML fragments on the server and injecting them into a div using div.innerHTML which was always fun during data changes. A template approach (see below) simplifies this dramatically. The {{ ‘products/’ + id }} syntax which basically says put the value of the id property into this expression will take a little getting use to but is similar enough with other markup syntax like XAML that it shouldn’t be to hard to pick up. The associated JavaScript code adds a behavior to the template that associates the data, template and element to facilitate repeated data binding.

<div id=”repeater1”></div>
<div id=”template1” class=”sys-template”>
  <h2><a href=”{{ ‘products/’ + id }}”>{{name}}</a></h2>
  <p>{{description}}</p>
</div>

<script type=”text/javascript”>
  Sys.Application.add_initialize(function() {
  $create(Sys.UI.DataView, {
    template: $get(“template1”),
    data: myData
  }, {}, {}, $get(“repeater1”));
}
</script>

There are other examples in the roadmap that show how to do this all declaratively by including various xml namespaces. I like this approach better since its closer to the way XAML works which for someone who moves between the two often helps keep my mind thinking consistently.

Data Binding

I am excited to see a new approach to client-side data binding in this new roadmap. In the early SDRs I thought the xml-script stuff was odd and didn’t feel that the approach would be a viable one. I am glad to see this has been revisited. I hope this approach will limit the use of update panels for partial page refreshes and possibly be incorporated into the ASP.NET MVC stuff to provide a clean way to do more work on the client. The HTML fragment below demonstrates the binding syntax {Binding flight, mode=twoway} which is identical to how XAML does it. This type of binding allows for bidirectional binding which is an absolute must when working with client-side data. I am glossing over a lot here so read the roadmap for a lot more information on how all of this code works.

<body xmlns:sys=”javascript:Sys” xmlns:dv=”javascript:Sys.UI.DataView”>

<div id=”tripList” sys:attach=”dv” dv:data=”{{myData}}”
    dv:template=”{{$get(‘template2’)}}”></div>

<div id=”template2” class=”sys-template”
  xmlns:ac=”javascript:Sys.UI.AutoComplete”
  xmlns:wm=”javascript:Sys.UI.Watermark”
  xmlns:dp=”javascript:Sys.UI.DatePicker”>
  <input type=”text” sys:id=”{{ ‘airport’ + $index }}”
    sys:attach=”ac,wm”
    ac:serviceUrl=”airportList.asmx”
    ac:minimumPrefixLength=”{{1}}”
    wm:text=”Type the name of an airport”
    value=”{Binding airport, mode=twoWay}” />
  <input type=”text” sys:id=”{{ ‘flight’ + $index }}”
    value=”{Binding flight, mode=twoWay}” />
  <input type=”text” sys:id=”{{ ‘date’ + $index }}”
    sys:attach=”dp”
    dp:lowerBound=”{{ new Date(1970, 4, 21) }}”
    dp:upperBound=”{{ new Date(2050, 1, 1) }}”
    value=”{Binding date, mode=twoWay}” />
</div>

Client Data Sources

The roadmap also talks about support for something called “live binding” where changes to data automatically propagate to update the rendered UI.

To support this Microsoft expects to implement a Client Data Source that can:

  • specify a source of data, such as an ADO.NET Data Service.
  • request data from the source.
  • cache data.
  • save changes back to source.
  • Expose methods such as insertRow.
  • provide collection-change events on cached data.
  • Client-Side and Server-Side Data as One

if they can pull this off the client development will be totally awesome!

Client Data and Server Data

I am also glad to see that the client data approach is combined with a server data approach. Many times a pure client-side approach requires a developer to go get data from the server after the page has been rendered. This has always seemed like a inefficient approach. In the early days of ASP.NET AJAX having a combined client/server data solution was one thing I had mentioned in the SDRs. It seems the ClientDataSource, ClientDataSourceExtender and the ClientDataView server controls will solve this problem for us providing the ability to work with data from both locations using a clean approach.

Summary

I am really excited about what is coming out of the ASP.NET Team in this area and looking forward to working with the bits. With Silverlight all the rage I am glad to see that we still haven’t forgotten that for real “reach” scenarios HTML and JavaScript are still going to be needed.

Silverlight IE Pains on Windows 2008

So I got an environment up an running to do some work with Silverlight Beta 2 and also SP1 for VS 2008. I decided to do all of this on a VMWare image with Windows 2008. Man was this a headache. The extra super stringent security on Windows 2008 made this an absolute pain. Just so others don’t have to go through the same thing I documented what you have to do to get things to work.

1. Turn off IE Enhanced Security (ESC) for Administrators (this assumes your are developing as an admin). This will enable you to open websites without getting asked if it’s ok. To do this go to Administrative Tools and open Server Manager. Click the Configure IE ESC link as shown below in red. This opens the dialog that allows you to turn off ESC for administrators and for users. I just turned it off for administrators on my box since that is what I am developing as.

ServerManagerIEESCsetting

2. Now that you have that done run you application in debug mode (which won’t show the Silverlight control yet) and add “http://localhost” to your trusted sites. I did this so that all of the other websites I hit will still have the standard “bullet proof” security. To get to the security dialog shown double click the Internet icon. Then select the trusted sites icon and finally add “http://localhost” to the trusted sites.

IESettings2008Silverlight

Once I did this I was finally able to rock and roll with Silverlight. If I remember right you will get a little warning just below the toolbar that ESC is disabled. If you select it you can turn this warning off.

I hope this helps.

Speaking at San Diego Code Camp

I will be presenting on two very different topics this year at the SoCal Code Camp in San Diego that reflect much of what I have been doing over the last 6 months or so. My first session Building Control Extenders using the Ajax Control Toolkit stems from the work I have been doing on my book and will be a fairly comprehensive look at creating controls using the Ajax Control Toolkit. My second session Overview of the Composite Application Guidance for WPF covers the work I have been doing with the Patterns and Practices Group on building composite applications in WPF.