Improve maintainability of ASP.NET databinding

Most of us (I think) don’t have full browser automated testing through Watir or Selenium.  Because of that, even though we have tons of automated NUnit tests, we could still have problem in web pages in ASP.NET because these aren’t fully tested with the build.

Even with Resharper, refactoring often leaves bad property references in databinding code that looks like this:

<%# Eval(“EmailAddress”) %>

If we get rid of the EmailAddress property on the object we’re binding (or rename it), this would break.

If we convert the above line of code to the following, we benefit from strong typing (and Resharper helps us out a little more).  We can precompile the web application to ensure all references in web pages still work.  After all, compilation is a low-level form of testing.  It would alert us of a bug.

<%# ((Customer)Container.DataItem).EmailAddress %>