Author Archives: Graham Mendick

Putting WebForms DataBinding front and centre

The previous release of Glimpse saw the introduction of first class WebForms support, bringing with it a contextualized view of both the Control Tree hierarchy and the Page Life Cycle. Glimpse WebForms development has been continuing apace and with this new release we’re delighted to shed some light on the previously dark art of WebForms DataBinding.

WebForms ‘DataBlinding’
DataBinding is to WebForms what ModelBinding is to MVC and is an essential ingredient in building maintainable and testable WebForms code. But until now, understanding when a DataBind occurs has been pretty much a mystery. For example, a change to the Page’s PostBack status or a Control’s ViewState mode can have dramatic effects on when DataBinds are triggered. Changing a DataBound Parameter value is another way to fire a DataBind, the Text of a TextBox for example, but keeping track of these values as the Page moves through its Life Cycle hasn’t been easy.

Glimpse to the rescue
We’ve added a new DataBinding section to the Control Tree tab. Alongside each DataBound Control we list the Page Life Cycle Events during which a DataBind was triggered for that Control. The screenshot below shows that the categoryList was DataBound once during the Page PreRender Event.

DataBinding Event

You may be thinking this information can only be displayed if you’re using the latest .NET 4.5 DataBinding approach, more akin to the ModelBinding architecture of MVC. But you’d be wrong. The Event information is displayed for all Controls inheriting from DataBoundControl, for example the ListView and FormView (but not the DataGrid or DataList), irrespective of how they were DataBound.

We haven’t stopped there. Together with the Event we also display the Parameters in play at the time the DataBind happened. The screenshot below shows the breakdown of the Parameters used when the productList was DataBound in the PreRender phase. The first Parameter looked for, but didn’t find, the id field in the QueryString; the second Parameter found a value of ‘Cars’ in the RouteData categoryName field.

DataBinding Parameters

Once again, this Parameter display isn’t limited to .NET 4.5 DataBinding. Provided the Parameters are registered using an ObjectDataSource, LinqDataSource or SqlDataSource the information can be extracted just the same.