Thursday, April 21, 2011

Knock Me Out

Knock Me Out: "Ideas, thoughts, and discussion about Knockout ( and related technologies (jQuery and jQuery Templates)"

Friday, April 08, 2011

Why I Still L.O.V.E. ASP.NET WebForms - John Katsiotis

This guy uses the Model-View-Presenter (MVP) pattern with ASP.NET WebForms. A Microsoft MSDN link is here; a Martin Fowler article here.

Why I Still L.O.V.E. ASP.NET WebForms - John Katsiotis: "We will use the MVP pattern and the open-source project WebFormsMVP to accomplish that! Can’t wait? Download the sample!"

Thursday, April 07, 2011

Don't mock HttpContext

Don't mock HttpContext: "It's so easy to take a direct dependency on HttpContext and not even realize it. If you're in the code behind in Web Forms or in a controller action in MVC, it's just right there, tempting you to use it to access session variables, application security, etc.

But don't."

Monday, April 04, 2011

dapper-dot-net - Simple SQL object mapper for SQL Server - Google Project Hosting

Wow. Impressive! Great for quick and dirty stuff, no? It uses dynamic types extensively.

dapper-dot-net - Simple SQL object mapper for SQL Server - Google Project Hosting: "Dapper - a simple object mapper for .Net
Dapper is a single file you can drop in to your project that will extend your IDbConnection interface."

Friday, April 01, 2011

Setting the Text of a ListControl in ASP.NET

If you try the following, it should set the visible text of the dropdown control in question, right?
    listControl.Text = "4 Year College";
Well, unfortunately, no! The "Text" property is named that way for consistency across all ASP.NET controls and refers to the form value that is passed to the server when the page is submitted. So unfortunately for me, the "Text" property silently rejected my attempt to set it and the page did not work.

You may be asking yourself why I am trying to set the visible text and not the value of the control. The reason is that the application I'm working on receives the displayed text from a web service and not the value that is passed in the form variables. Why not create a dictionary, look up the the text string in the dictionary, and pass that to the control?

The answer? I already have a dictionary. It's called the SELECT control itself. The generated HTML for my control is, say, the following:

This control is essentially a dictionary of key-value pairs: the key is the value attribute of the option tag, and the value is the visible text that is displayed for the given item in the dropdown list. So in the spirit of Don't Repeat Yourself (DRY), I wrote a extension function to allow me to set not just the value but also the text. I give you ListControlExtensions.cs:

Here's a typical usage. In this particular scenario, my data should be scrubbed, but if not I log a warning: