OdeToCode IC Logo

All The News That Is Fit To Print (Oct 19, 2004)

Wednesday, October 20, 2004 by otcnews

It's been a busy, busy nine days since the last OTC Link Blog post. Let's see what is interesting:

Evaluating The DataBinder

Wednesday, October 20, 2004 by scott

I was trying to put together a quick piece of code as an example over the weekend and remembered how much I dislike using DataBinder in ASP.NET.

Let’s say a web service call gives back an array of simple objects (the sort of objects you’d see imported by a web reference):

class Parameter
{  
 public string Name;
 public string Value;
}

I wanted to dump the Parameter array to a web page as easily as possible. The following will not work.

<asp:Repeater id="Repeater1" runat="server">
   <ItemTemplate>
      <tr>
         <td>
            <%# DataBinder.Eval(Container.DataItem, "Name") %>
         </td>
         <td>
            <%# DataBinder.Eval(Container.DataItem, "Value") %>
         </td>
      </tr>
   </ItemTemplate>
</asp:Repeater>

The DataBinder, besides looking awkward, only finds public properties - it doesn’t find public fields. The quick hack to get around this is to replace the language agnostic DataBinder syntax with C# code:

<asp:Repeater id="Repeater1" runat="server">
    <ItemTemplate>
        <tr>
            <td>
                <%# ((Parameter)(Container.DataItem)).Name %>
            </td>
            <td>
                <%# ((Parameter)(Container.DataItem)).Value %>
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

Disadvantages:
There is a huge disadvantage in that if the Parameter class fields ever change, the code in the ASPX won’t generate an error until runtime. It’s also a problem if the ASPX moved from a C# project to a VB.NET project.

Advantages:
To me the second example looks cleaner – I can see an object and a property even through the parentheses of a cast. It’s also blazingly faster - two order of magnitude faster. In fact, in my tests the following:

<%# DataBindParameterName(Container.DataItem) %>
// in the code behind of the class:
protected string DataBindParameterName(object o)
{
    return ((Parameter)o).Name;
}

is still 300x faster than the reflection machinations DataBinder.Eval uses. Food for thought in perf critical scenarios.

Three Things I Learned In Boston

Wednesday, October 20, 2004 by scott
  1. Navigating Boston with the aid of a speech enabled GPS device is about as useful as navigating Boston with the aid of a chatty 3 year old. “TURN LEFT”, the device says. Ok. Would that be the street 30° to the left or the street 60° degrees to the left? This happened more than once. Note to self: write down street names on next trip.
  2. I need to install Windows SharePoint Services and find out what all the hoopla is about. After hearing about SPS in the hallways and seeing it in a presentation, I want to learn more.
  3. It is possible to live on pizza, sushi, and diet coke for three days.

Slides and Code From The Camping Trip

Tuesday, October 19, 2004 by scott
Codecamp2.zip contains the slides and code from my presentation on integrating SQL Server Reporting Services with ASP.NET.

The code includes one web project to demonstrate:

  • URL access to the report server
  • A simple demo of the ReportViewer component
  • Building a TreeView of report items with a web service call (ListChildren)
  • Examining report parameters – their valid values, type, dependencies, and state with multiple web service calls to GetReportParameters

The second project delivers a report to a second ASP.NET application (a .Text blog) via a web service call. For more information on this project, see my post: The Blog Delivery Extension.

Kudos to Thom Robbins, the other MS folks, and all of the speakers for a great weekend.

Code Camp II

Friday, October 15, 2004 by scott

If you are coming to Code Camp 2 this weekend, I hope to see you at my talk Saturday afternoon on integrating SQL Server Reporting Services and ASP.NET. This session is not about designing reports, it’s all about integration: URL access, web services, and delivery extensions. These topics are useful for SSRS integration with any type of application, actually, but the session does focus in on particular points of pain in an ASP.NET environment. I’ve been through the pain, and I can pass along tips to make it easier for others.

At some point next week I’ll get the code examples and slide deck onto OdeToCode.com.

I can’t wait to attend the other presentations and chalk talks, they look great. There are a boat load of bloggers coming:  DonXML, Scott Watermasysk, Kent Tegels, Chris Pels, Carl Franklin, Jason Bock, Robert Hurlbut, Chris Bowen, and Sam Gentile. Who did I miss? There is and even a book swap. Like any camping trip, I'll probably need two days to recover and return to normal life. Not that life is entirely normal all the time.

Some Things Just Say "Hack Me"

Tuesday, October 12, 2004 by scott
Everyday I pull into work I see this sign. The sign is of the type you typically see over an interstate highway, but this one sits at the end of a road, behind a government office building that leases space to private companies. I’ve often wondered why the sign was here - at the end of a road with nowhere to go but a parking lot. I’ve never seen a message appear on the sign. I don’t know who controls it. I’ve concluded someone in the government needed to spend some end of the year money in order to pad next year’s budget.

The other day as I was leaving, the sign spoke to me in a clear voice.

“Hack me”, the sign said.

“Huh?” I replied.

“Make me display something funny. I want to make people laugh”, the sign said in a firm but pleasant tone. “Hack me”, it repeated.

It took me a moment to gather my thoughts. I’ve amused co-workers with printer tricks, but this was a tall order. About 35 feet tall.

“You’re nuts”, I replied to the sign. “Most of the people around here are government bureaucrats – they have no sense of humor. I could get into big trouble”.

The sign spoke in a soothing, almost hypnotic voice. “You know you want to do it. You want to find out how to light me up. It’s been a long time for me…”. The voice faded, then returned in the kind of soft, neutral voice that only a talking sign could have. “Hack me in the old-school sense of the word, you know you want to do it”.

I paused to think again and began to feel uneasy. What if someone saw me talking to this sign? Not everything in Columbia, Maryland is as it appears. Why, just around the corner behind a second tree line is a large, unnamed brick building with few windows, two layers of barbed wire fence, and cameras every 200 feet. The NSA moved in, some say, but no one really knows. Someone could be watching.

I moved to my car and tried to ease the sign’s voice out of my head with talk radio. As I pulled out of the parking lot and headed towards the highway, I began to feel I was driving suspiciously slow. I decided I needed to blend in. On the entrance ramp, I slammed the accelerator to the floor and veered hard to the far left lane, all the while gesturing rudely at the faceless cars around me. I felt more inconspicuous with this behavior, which is typical among the breed of commuters in the Baltimore / Washington DC corridor.

My thoughts returned to the sign on the drive home. If the opportunity presents itself, I thought, I should at least have some idea of the message I’d put up. Typically, these signs display something obvious and completely unhelpful. Like when you can see nothing but the brake lights of stopped cars in the distance, these signs will display “CAUTION : CONGESTION NEXT 2 MILES”.

A message like “CAUTION : TREES AHEAD” would be exactly the type of message people would expect to see on a highway sign in front of a forest on a dead end road. It might be so obvious and so un-helpful (in other words, so sign-like), that nobody would ever notice. Nobody except me, of course, and the lonely sign. Not that I'm ever going to touch the sign. Never. Ever.

If you had a giant sign outside of your office, what would you make it say?

Notable Posts - October 10, 2004

Monday, October 11, 2004 by otcnews

Girish Bharadwaj looks at new screen scraping techniques in Whidbey.

Feroze Daud covers asynchronous programming with HttpWebRequest.

Manish gives some insight into the CallContext class.