|
With the release of ASP.NET 2.0, Microsoft has given us some new Webcontrols that allow us to exercise a more 'Declarative' approach to website development. This is an approach that I use strongly in my current ASP.NET development and have found beneficial in many ways. In ASP.NET, declarative programming is accomplished through the use of webcontrols. Many of us already use this technique when we use the suite of existing webcontrols. Our page incorporates webcontrols and through setting properties and calling methods, accomplishes tasks which would otherwise take much more code. 2.0 gives us some new webcontrols which let us save even more code at the page level. Remember, Declarative Programming lets the page tell webcontrols 'what' to do and the webcontrols decide 'how' to do it. In the case of the built-in controls, the code has been done for us, but in the case if custom webcontrols, we're just moving certain code off the page and into a set of controls.
Microsoft's new controls for ASP.NET include the GridView, DetailsView, FormView, and a set of DataSource controls.
The GridView is a new and improved DataGrid and among other things, it has eliminated the need for us to provide underlying code for sorting and paging. The DataGrid supported this functionality only so far by adding links on the grid and raising some events. We still had to provide the data rebinding and grid refreshing code. The GridView now encapsulates this code inside the control's source code.
The DetailsView pivots a single record and displays the fields top-to-bottom with their values next to each field. The control supports binding and paging just like the GridView.
The FormsView uses templates to create a data-entry form for a record in its datasource. This controls lets us edit, delete, and insert records from and to a datasource and saves us the time for building a data-entry form normally made up of many labels, textboxes, buttons, etc.
All the above controls fully support multiple templates for even further customization. From what I've seen, templates have not changed from the way they were handled in the current ASP.NET, both visually and programatically.
Additionally, we've been provided with a small suite of DataSource controls. The SqlDataSource control for example, let's us declare database information, including connection, retrieval query, and update query in a webcontrol. This control can then be bound to any of the above-mentioned webcontrols.
With these new controls, I've setup a grid of table data, as well as a data-entry form for its records -- all without a single line of code. This declarative approach is one I've been using for a while inn my ASP.NET development. Creating custom webcontrols to house visual elements also allows me to use any object-oriented technique when programming my visual elements. I've created 'form-view' type controls to do data-entry which all inherit from a class that provides common visual elements for my data-entry forms, like headings and buttons and other things. If you want to see an Microsoft example of an entire form created with a webcontrol, check out another new Webcontrol ASP.NET 2.0 has called the ChangePassword control.
If you've not yet started to play with Visual Studio .NET 2005 (specifically ASP.NET 2.0), these new webcontrols should really wet your appetite. Feel free to contact me if you need any help.
|