Sergio and the sigil

IE8 Readiness and IETester

Posted by Sergio on 2008-12-15

Today I started researching and preparing my application for IE-8, or at least knowing what we would need to take care of before its release sometime next year.

I started by downloading the VPC image with IE8 beta 2 because it seemed much more convenient than setting up a new virtual machine with XP or Vista from scratch. Well, life's not easy, is it?

VPC. Hyper-V. Fight!

I use Hyper-V instead of VPC, so I promptly imported the .VHD file into a new, empty virtual machine and booted it off. It worked! Not so quick... The VM was not recognizing the Hyper-V virtual hardware (Ethernet included) because I needed to install the Hyper-V enhancements (Integration Services Setup). Well, that would require me to first uninstall the VPC's Virtual Machine Additions that came with the VM. No problem, I've done that a few times before. Nope. Cannot uninstall because the "Add or Remove Programs" applet had been intentionally disabled in this VM. I searched a little bit and could not find the password for the admin account so I figured at this point it would be easier to just go ahead and create the whole thing from scratch after all.

UPDATE: The passwords for the VPC image are in the accompanying Readme.txt file, which I had not thought of reading. Blame me.
To enabe the "Add or Remove Programs" again, go to the registry at HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Uninstall find the value named NoAddRemovePrograms and delete it or set it to zero.

IETester

That's when I came across the IETester utility. This little gem allows you to open, side-by-side, IE5.5, IE6, IE7, and IE8 Beta 2.

When I saw this I thought: Nah. They're probably just tweaking the DOCTYPEs and tricking IE8 into rendering under some layout mode equivalent to the other versions. I installed it anyway and it turns out that IETester only needs IE7 to run.

Feeling a little puzzled I went snooping and in its installation directory I saw this.

Holy Moly. They are indeed running the actual rendering engines side-by-side. Note the familiar shdocvw.dll and even the Internet Options applet (inetcpl.cpl) from each browser version. I did not know you could redistribute IE binaries like that. Can you?

Anyway, I'm keeping a copy of this installer just in case Microsoft decides to make one of those unhelpful moves and demands that it is taken down. It will certainly help me in the coming months.

Talk: JavaScript - Beyond the Curly Braces

Posted by Sergio on 2008-12-09

Next week I'll be speaking at the Lake County .NET Users' Group, in Grayslake, IL. The topic will be something that is near and dear to me and which I have talked and written about quite a number of times.

If you live in the North 'burbs, come and support our local group. You can register for this event here.

JavaScript - Beyond the Curly Braces

One of the greatest problems with JavaScript is its superficial syntax resemblance of C-style languages. We call it the curse of the curly braces.

That is also a very large source of frustration for developers trying to learn JavaScript beyond the basics. Thinking that JavaScript is somehow related to Java or even "It's almost like C# but a little simpler" is an unfortunate and common occurrence that can only lead to trouble.

In this session we will analyze some of the fundamental differences between JavaScript and C#/Java. We will highlight the pitfalls that can trap us and the appropriate workarounds for them.

Time permitting and if there's interest we will take a look at Idiomatic JavaScript, which will help us understand how JavaScript is being written these days. Learning about this will also help you when trying to read the source code or even the documentation and samples for popular JavaScript libraries like jQuery, Prototype, YUI, etc.

Trying out a Randori

Posted by Sergio on 2008-12-08

Tonight's meeting of the Software Craftsmanship Group was led by Uncle Bob Martin.

This time around we tried a Randori-style coding dojo. The task was to build a clock and, although we fell short of the original goal of having a GUI, there was plenty to be learned in this process.

I felt it was an interesting way to learn about your own performance under a moderate amount of pressure. More importantly, at least for me, was getting exposure to BDD and pairing with other developers that are a few step ahead of me on that particular road.

Once again, because I'm not a Ruby developer by day, I felt a little bit uneasy taking my turn and going up there to code a little bit. But I would not pass the experience, otherwise why even bother showing up for the event at all.

The whole thing was captured on tape. Hopefully the video will be made available and I'll come back and link to it here.

UPDATE: Doug has put some videos up.


Software Craftsmanship - Coding Dojo - Kata


Software Craftsmanship - Coding Dojo - Randori

Reusing Views in ASP.NET MVC for Ajax Updates

Posted by Sergio on 2008-12-05

The other day I came across this post in Marteen Balliauw's blog where he demonstrates and interesting way to make the same ASP.NET MVC view render correctly from both a regular request and an Ajax request.

In Marteen's post he uses a custom ActionFilterAttribute to detect the Ajax call and replace the standard master page with an unadorned Empty master page.

I liked the idea that you can add that behavior to any action simply by bolting that attribute to it.

What I'm going to illustrate here is a variation of that idea that can be used when you have your own base class to all your controllers, which is something I always do.

SIDE NOTE: I have the habit of creating base classes for all the important things in my ASP.NET applications right after I create the project. I carried this habit from the ASP.NET Webforms-style to the MVC projects. So I typically have ApplicationController, ApplicationView<T>, PartialView<T>, ApplicationMaster, etc. These classes start off empty but code starts finding its way to them rather quickly.

What I'm going to do is override the Controller.View() method to detect the Ajax calls and replace the master page right there.

public abstract class ApplicationController: Controller
{
  protected override ViewResult View(
            string viewName, string masterName, object model)
  {
    if(IsAjaxRequest)
      return base.View(viewName, "Empty", model);

    return base.View(viewName, masterName, model);
  }

  protected virtual bool IsAjaxRequest
  {
    //Both Prototype.js and jQuery send 
    // the X-Requested-With header in Ajax calls
    get
    {
      var request = ControllerContext.HttpContext.Request;
      return (request.Headers["X-Requested-With"] == "XMLHttpRequest");
    }
  }
}

With that in place I don't need to change anything in my action code to start supporting the Ajax calls (as long as the controller inherits from the above base class)

public class SampleController : ApplicationController
{
  public ActionResult Index()
  {
    return View();
  }

  public ActionResult Details(int id)
  {
    var user = new UserInfo {Name = "user" + id, Age = 30};
    return View(user);
  }
}

My Index action calls the Details action using both a regular request and an Ajax call, for the sake of the example.

<%@ Page Title="" Language="C#" 
  MasterPageFile="~/Views/Shared/Site.Master" 
  AutoEventWireup="true" 
  CodeBehind="Index.aspx.cs" 
  Inherits="MvcBeta1.Views.Sample.Index" %>
<asp:Content ID="Content1" 
        ContentPlaceHolderID="MainContent" runat="server">
<h2>Sample View Index</h2>
<%= Html.ActionLink("Go to Details", "Details", new { id = 123 })%>
<hr />
<input type="button"  id="loadDetails" value="Load with Ajax" />
<div id="detailsDiv" style="background-color:#aaa;">
[details should load here]
</div>

<script>
  $(function() {
    $('#loadDetails').click(function() {
      $('#detailsDiv').
        load('<%= Url.Action("Details", new {id = 123}) %>');
    });
  });
</script>
</asp:Content>

The Details view is trivial. It's just a table.

<%@ Page Title="" Language="C#" 
  MasterPageFile="~/Views/Shared/Site.Master"
  AutoEventWireup="true" 
  CodeBehind="Details.aspx.cs" 
  Inherits="MvcBeta1.Views.Sample.Details" %>
<asp:Content ID="Content1" 
        ContentPlaceHolderID="MainContent" runat="server">
  <h2>Details for <%= ViewData.Model.Name %></h2>
  <table border="1">
    <tr><th>Col 1</th><th>Col 2</th><th>Col 3</th></tr>
    <% for(int i=1; i<= 5; i++) { %>
      <tr>
        <td>cell (<%= i %>, 1)</td>
        <td>cell (<%= i %>, 2)</td>
        <td>cell (<%= i %>, 3)</td>
      </tr>
    <%} %>
  </table>
</asp:Content>

When at the Index page we can click on the "Go to Details" link and see the full rendering of the Details view.

If we had instead clicked the "Load with Ajax" button we would cause a simpler version of that page to be inserted in the detailsDiv element (note that the tabs and the blue background that surrounds the table did not come in the rendered content.)

Of course, ASPX files are not the indicated place for placing content that can be used in partial updates, ASCX files would be a better choice for that. That said, sometimes it can be really convenient to have this ability.

Chicago ALT.NET Lightning Talks

Posted by Sergio on 2008-12-01

For this month's of meeting we will be doing something we had been thinking about for a while. With so many members that always bring interesting contributions to our meetings, we will just have an open projector night. I'm looking forward to this one.

Lightning Talks

6:00 pm
Pizza and networking time

6:30 pm
We do not have a set topic for this month. Instead we chose to have lightning talks where anyone can sign up on the spot for a 10 to 20-minute demonstration or presentation about anything he/she considers interesting.

This can also be a nice opportunity if you have never talked to a group and would like to try a short version first.

There's no agenda set for the talks to be given but here are a few that were already proposed by someone.

  • LINQ to SQL
  • AOP in MVC
  • XmlBuilder

If you want to talk, just show up. If you want to include your talk in this page, let us know.

7:45 pm
You may want to stick around after the presentation portion of the meeting and take part in our monthly open discussion. The topic is never arranged in advance but it's common that it reflects the content of the presentation.