| By Alan Fisher | Article Rating: |
|
| November 11, 2003 12:00 AM EST | Reads: |
13,271 |
Data table displays are the workhorses of transaction- based Web applications. So why are they so hard to build, especially since .NET provides a built-in ASP.NET DataGrid control? The reason is that, like all databound controls, data grid applications are not standard or necessarily predictable. Building them is so hard precisely because they demand custom treatment for each new application.
Consider the difficulty of fulfilling each of these pretty standard requirements:
The task of customizing data validators is one of those "creeping" tasks – while not difficult coding per se, it quickly becomes mind-numbing when you consider that every editable field on every page of your application has two to three relevant Validators that may require customization.
In fact, one of the most enduring problems of writing user interfaces is figuring out how to display large amounts of custom data efficiently and intuitively without bewildering the user. The problem becomes particularly thorny when the interface must reflect hierarchical relationships within the data that the user needs to modify.
However, while ASP.NET and Visual Studio .NET have certainly made Web application development simpler, efficiently creating intuitive, application-appropriate data grids still involves significant hand-coding and a mastery of the .NET Framework. And you must ask yourself whether investing a lot of effort in customizing DataGrid controls is really the best use of your time.
The Code Generation Alternative
There is an alternative to building custom DataGrid cond trols by hand: code generation. This article describes how advanced automatic code generation can quickly create customized DataGrid controls for the .NET Framework that let developers effectively solve the problems of complex displays, sophisticated data entry, and large data sets.
Complex Displays
The most sophisticated of today's code generators generate databound applications based on code generation instructions you provide within your application's HTML. These instructions can take the form of XML-based "code generation tags" that specify the individual databound controls you want within the page – the DataGrid controls, filter controls, search facilities, and navigation controls. When the code generator is run, it converts these code generation commands into a combination of presentationlayer ASPX pages containing the actual controls, application-layer code-behinds and application logic, and database-layer SQL statements and transaction management code.
The sample job application site shown in Figure 1 was generated using the Iron Speed Designer code generator with code generation tags inserted into an HTML layout page file. Each job application is a row in the data grid and includes two additional tables within the row – employment history and education. The code generation tags are illustrated in Figure 2.

Figure 1

Figure 2
When you consider the difference in time and programming effort to insert one code generation tag into an HTML page as opposed to hand-coding all the ASPX, C#, or Visual Basic codebehinds – plus SQL statements for each control – it is easy to see how quickly a code generator saves you significant time.
Some of the advanced functions enterprise-class code generators can handle include:
Data Entry
Many data grids serve their purpose as simple tabular data displays. However, many CRM, contact management, and other back-office Web applications also need to offer forms input functionality to application users.
ASP.NET offers some shortcuts to make fields editable. However, making an entire data grid editable or allowing editing of template columns (using dropdown menus, for example), requires an advanced knowledge of ASP.NET. A state-of-theart code generator will allow you to make individual data grids or entire forms editable without hand coding (see Figure 3). Dropdown lists, radio buttons, and other controls should also be options for any data grid.

Figure 3
Efficiently Managing Large Result Sets
The standard ASP.NET DataGrid control fetches the entire result set from a database query into the .NET application layer, even if that result set has millions of rows. This leaves the application layer to do the heavy lifting – sorting and filtering – activities best left to the database rather than the application. Manipulating large datasets in the application layer can have huge resource implications for applications.
To minimize the data transmission load and the application's memory storage requirements, many application developers employ database cursor management – a conventional, wellestablished database technique – to manage the number of records downloaded from the database with each data grid page request. A code generator can generate cursor-management code that retrieves one page of data at a time, and only when requested, rather than retrieving the entire data set.
Managing the "state" of your application pages without dragging down performance is one of the most difficult challenges for Web application developers. When cursor management is employed (see Figure 4), the application program doesn't attempt to maintain the data set. When the next page (or any other page) is requested, the generated application program simply passes the request to the database layer, where the appropriate SQL query is run again to request the needed page's data. The query parameters include the page number requested and the batch size, which is the number of records per page.

Figure 4
Moreover, the SQL query is rerun so that any records added or deleted since the previous page fetch are properly accounted for. By contrast, if the cursor were simply maintained, any data updates would not be reflected when going from page to page.
Custom Data Validation
In .NET, data validation is done using a series of validation server controls, or "validators," for each editable field value that is displayed in a page. These validators are attached to various Forms controls. Three basic validators are required for nearly every editable field:
Note that additional validators may be needed for some fields. For example, if you set a limit of 11 characters for a phone number, you need to add a FieldValueTextLength Validator to ensure that an error message is generated if the phone number is not entered correctly. Full-featured code generators will generate these three required validators for each field, as well as others (like FieldValueTextLength) as needed.
Let's look at a simple example. Note: This example uses Visual Basic .NET code, but the process is very similar if using C#.
The real action happens in the RecordCustomControlValidator, where we customize and extend the default validation. This specific example extends the base RecordControlValidator for the "city" field to enforce a requirement that the city entered matches the shipping address for this record.
In .NET, the base record control has two methods that allow custom validation:
Override these methods to add your own custom logic.
In an application generated by Iron Speed Designer, two classes are generated: the first is a "generated class" that is updated with each regeneration; and the second is a "safe class" that is never regenerated and preserves your custom logic.
Example: Edit Customers Page - Validate city field
EditCustomersRecord.aspx
EditCustomersRecord.safe.aspx.vb
EditCustomersRecord.gen.aspx.vb
Data Validation: In the City field validation example shown in Listing 1, we add additional logic to the "safe class" in order to override the validateData function. A safe class is generated once and never overwritten. Thus, it does not have to be rewritten for future applications if your code generator can adopt it and make it available for future development efforts
After acquiring the City field, we compare it to "Mountain View". If the City is not Mountain View, then we return "False," generating an error message and keeping the user on the page. If the validator returns "True," the user proceeds to the next page.
Note that the custom validation function is called every time the user clicks any button that requires validation. Thus, the "submit" button calls the custom control, runs the validation, and, if "True", continues the process. The "cancel" button returns "False" and aborts the process.
This example is made simpler by the fact that it builds on generated code. Clearly, using a code generator to automate the composition of the several generated validators for each field (usually the three discussed earlier: RequiredField, FieldValue, and RecordControl Custom Validator) saves you significant amounts of work. The generated code can then be extended and modified for fields that require further customization, as illustrated in our City field customization example. When selecting a code generator, also make sure that your custom validations can be reused for subsequent applications, in order to leverage code assets across your entire organization.
This Ain't Your Father's Code Generation
Generated code can and should match the caliber of code written by senior developers – the developers you wish you could clone. Some of the scalability and performance enhancements provided by today's code generators include the ability to run on multiple servers, concurrency management, and optimized application performance in a .NET environment.
In summary, code generation offers the following benefits:
Getting advanced custom features "for free" from your code generator is more efficient than hand-coding ASP.NET from scratch. Make sure the code generator you choose (or build yourself ) achieves the level of performance and quality described in this article.
Published November 11, 2003 Reads 13,271
Copyright © 2003 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Alan Fisher
Alan Fisher is cofounder and chairman of Iron Speed, Inc., maker of Iron Speed Designer, the popular application generation software for rapidly building Microsoft .NET web applications. The pain of building enterprise-class web applications from scratch inspired Alan and his partners to launch Iron Speed and simplify and accelerate web application development, particularly for the growing number of .NET web application developers.
![]() |
rajelyas 02/02/09 11:33:00 AM EST | |||
I thank this site for giving such vital information on code developing. This knowledge will help us find better jobs in the period of recession and serve fruitfully the society. Raj |
||||
- Kindle 2 vs Nook
- Practical Approaches for Optimizing Website Performance
- SQL Anywhere Server and AJAX
- PowerBuilder Top Feature Picks
- The Difference Between Web Hosting and Cloud Computing
- PowerBuilder 12 and .NET
- Contrary Opinion: Why Silverlight is Good for Adobe
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Wave on Ulitzer: Confessions of a Google Wave Fanboy
- Cloud Computing Best Practices
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Rich Content Rotator for ASP.NET
- RIAs for Web 3.0 Using the Microsoft Platform
- Kindle 2 vs Nook
- Practical Approaches for Optimizing Website Performance
- Social Media Terrorists
- SQL Anywhere Server and AJAX
- SYS-CON's Cloud Expo Adds Two New Tracks
- PowerBuilder Top Feature Picks
- The Difference Between Web Hosting and Cloud Computing
- Google Maps and ASP.NET
- Crystal Reports XI & How It Has Changed
- Converting VB6 to VB.NET, Part I
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- How to Write High-Performance C# Code
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Implementing Tab Navigation with ASP.NET 2.0
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"
- .NET Archives: Getting Reacquainted with the Father of C#


































