ASP.NET 4.0 Enhancements

These days the majority of projects I’m involved in use ASP.NET 2.0, so I’ve been following closely what Microsoft is including in its next installment of its .NET Framework. Some of the new features and enhancements are going to be a nice touch, and quite rightly so. I won’t go into all of them now, but here is a few that I think will make web development a little less frustrating when it comes to web forms.

Client ID’s
Yes! Finally control over client ids! How many times have you just wished you could control the client id being set by the server when doing DOM manipulation in JavaScript. Well now with ASP.NET 4.0 you can with ClientIDMode, an enumeration property capable of 4 values.

  • Legacy: Behave as asp.net 2.0
  • Static : The ClientID value is set to the value of the ID property
  • Inherit (default): Get the value from the parent
  • Predictable: Used for controls in data-bound controls. ClientID is concatenated with the ClientID value of the parent naming container with the ID value of the Control. If using a gridview or listview you can append a datasource field.

ViewState
I know, ViewState is a complicated beast, however very useful. But I’m not going to try and explain the voodoo that is ViewState.  Currently if you want to disable viewstate for a certain control or page, it was a simple thing of setting the “EnableViewState” to false. However all child controls inherited this property. To get around this you would have to single out every child control you wanted to disable, and leave the one you wanted enabled.  Bring in ASP.NET 4.0’s ViewStateMode. Basically its used the same as EnableViewState, but you can then re-enable a child control if the parent has its ViewState disabled.

I am looking forward to having access to these new features, especially the ViewStateMode. Although not having them hasn’t been a major stumbling block in development, but what they add is the ability to have more elegant code, and were all striving for that!