By submitting your personal information, you agree to receive emails regarding relevant products and special offers from TechTarget and its partners. You also agree that your personal information may be transferred and processed in the United States, and that you have read and agree to the Terms of Use and the Privacy Policy.

A key component of any software development project is the user interface. Without a robust and well designed interface, you can end up discarding even the best-architected application. The graphical user interface (GUI) is the first, and usually only, face users see when working with your application. It forms the basis of their opinions and gives the critical first impression to users.

One of the challenges of Web development is developing a rich-client look and feel using the basic tools of HTML and JavaScript. Robust and interactive interfaces are possible with this technology but only with a great deal of effort and time. ASP.NET helps clear these hurdles. With ASP.NET, you can present rich-client features to the user quickly and easily using a thin-client delivery method. In this article, I'll give you 10 tips for creating and delivering these types of solutions.

Use SmartNavigation

The first way to make your browser-based applications feel more like traditional Windows Forms applications is to use the SmartNavigation property from the ASP.NET page document. Smart navigation helps solve the problem of screen flicker when a page requires a postback to complete an operation. When enabling smart navigation, ASP.NET persists the scroll position and focus between postbacks.

Setting this property also means keeping only the latest page state in the user's browser history. Smart navigation works only with up-level browsers and won't cause any rendering issues for down-level users. Enabling smart navigation is easy: Simply set the SmartNavigation property to True in the page's @page directive:

Another option to consider when developing ASP.NET-based interfaces is to use independent component publisher (ICP) controls. The advanced controls Visual Studio .NET provides allow you to create quality applications, but ICP controls give you the ability to create superior applications because they contain additional valuable features. ICP controls also fill holes the default controls don't address.

Many developers are familiar with using controls in the Visual Basic development environment, but few developers realize the potential of using controls in ASP.NET. These controls work by sending standard HTML and JavaScript to the browser. These controls can render on any browser using standard Internet technologies without any of the issues and security concerns surrounding ActiveX controls (see Figure 1).

Figure 1.Through the use of ASP.NET and ICP controls, you can bring rich-client features and functionality to browser-based applications. Here, full-featured graphs are rendered on the server side, but they can interact with the data table in real time via client-side JavaScript.

Be careful when you use of either the included controls or ICP controls on your Web pages. As a general rule, if you don't need the advanced features or the ability to interact with a control on the server side, you should use the HTML equivalent. Often, developers overuse controls on a page, such as using an ASP Label control for static text display. In such a case, you could use either a Div tag or Span tag more effectively. Every control placed on a page increases the overall server processing that must occur and puts a greater load on the Web server, thus increasing the response time for the page. The amount of increase in page-load time and the maximum number of requests per second your Web server can handle both depend on the amount of ASP controls you can replace with an HTML equivalent.

Add common functionality with user controls

One of ASP.NET's new features is the user control, which helps simplify the development of great user interfaces. User controls allow you to build your own custom controls from any other control. You can apply this to every page in your application rapidly by packaging common functionality into a reusable package. A great example of this is a menu that will be rendered on a high percentage of your Web pages. By encapsulating this functionality into a user control, you can drag and drop the control onto a Web page and move on.

Because the user control contains all the presentation and code, maintenance is reduced -- when you update the user control, all your pages will be ready to go.

For instance, the following user control adjusts the hyperlink based on the value set on the control's SourceURL property. You could position this user control on every page to provide consistent navigation to resources such as help files:

HTML has limited abilities, and one common challenge in Web development is creating complex graphics dynamically. You can overcome this hurdle by using the extensive capabilities supplied in the .NET Framework's System.Drawing namespace. With System.Drawing, you can perform rich server-side image generation and manipulation such as overlaying, resizing, and cropping images. If the content type is set correctly, you can output the results to any standard I/O stream (see Figure 2). Because both the browser and server treat the results as an image, you can use the ASP.NET output cache to increase your application's responsiveness.

Figure 2. This image was rendered dynamically on the server using the functionality exposed by the System.Drawing namespace. Images such as basic drawings can be generated on the fly and streamed to the browser via the standard I/O stream.

The next code snippet is the page declaration for the SystemDraw Web page. You must switch the content type to image/gif because you're only sending the browser a dynamically created gif file:

Figure 3. The DrawDemoGraph function does the work of generating the bars for your graph and rendering the image with the basic functionality of the System.Drawing namespace provided by the .NET Framework. You can leverage the built-in libraries to create your own complex custom images.

Make apps responsive: Stay on the client side

Creating a great-looking interface is only part of the battle. Even the best-looking applications will fail to gain acceptance if the interface is slow and unresponsive.

One approach to increasing the responsiveness of your application is performing as much as possible with client-side JavaScript instead of using server-side events. Client-side JavaScript's ability to work without the need for a round trip back to the server gives the user an instant response and removes overhead from both the network and Web servers. Some controls, such as the required field validator, generate JavaScript for up-level browsers automatically. Other controls, such as the custom validator, require you to write some JavaScript to perform their functionality on the client side (see Figure 4). Many advanced ICP controls expose a large section of their API in both server-side and client-side events.

Figure 4. This client-side function responds to the client-side events for the mouse-over event of the chart on the page. The function is passed the data points for the currently selected row and column. Then, the function changes the image on the corresponding row and column in the table on the page to show the arrow images. The function also changes the image in the correct cell to underline the data.

Expand the DataGrid

DataGrid is one of the most commonly used and most powerful inbox controls. Because of DataGrid's complex nature, it's an excellent candidate to extend with client-side JavaScript. One of the most common requests is to make DataGrid display a confirmation box on a record delete. Though the JavaScript to perform this operation is simple, the challenge is to wire the OnClick event of a ButtonColumn to the JavaScript.

To connect to the event, you should use DataGrid's ItemCreated event. This event fires as each row is rendered in the grid. During the processing of this event, you will acquire a reference to the command button in the row and associate the Dynamic HTML OnClick event to the custom client-side JavaScript:

As more applications are designed as Web sites and are called on to extend across language and cultural boundaries, developers are faced with the challenge of making applications global in scope. Many classes in the .NET Framework -- and, by extension, in ASP.NET -- are culture-aware. To access this awareness, you need to create a CultureInfo object to represent the current culture and associate it with the running thread's CurrentCulture property. Once this link has been made, common functions such as String.Format and DateTime's ToShortDateString will adjust according to the culture formatting.

ASP.NET must look at the Accept-Language header of the HTTP request to determine a user's culture request. ASP.NET will expose this header as a string array under the UserLanguages property of the Request object.

Adding some code to the Global.asax file's Application_BeginRequest event will allow you to create the CultureInfo object for the correct language (see Figure 5). Once you have created the CultureInfo object for the user's primary language, it will need to be associated to the current thread processing the request.

Getting ASP.NET formatting data according to each user's culture preference might be just the first step in making your application span the global community. But in many cases, it might be the only step needed.

Figure 5. Adding just a few basic lines of code to the Global.asax file will allow the .NET Framework to format your text to a user's regional settings automatically.

Add row numbers

Users often ask for the look and feel of Microsoft Excel in an application's data grid. One feature requested often is a set of row numbers on the grid. Using DataGrid's OnItemCreate event allows a sequential set of numbers to be added to the grid as each row is rendered.

Add a template column as the first column of the grid. As each row is rendered, the code behind the OnItemCreate event will update the text of this column based on the row index from the dataset. Each row of the dataset has an index property that can be used to compute the row number:

Pressing the Enter key on an ASP.NET form doesn't necessarily cause a form submission. To force a particular button on the page to fire and cause a postback on Enter, simply add one line of code:

Page.RegisterHiddenField("__EVENTTARGET", "BUTTON_NAME")

Change BUTTON_NAME to the ID of the button to which you want to default. This trick is limited by certain controls in HTML, such as a multiline textbox in which the default action is to create a new line.

Create wizard interfaces with Panels

The wizard-based interface has become a mainstay in client-server applications. Although ASP.NET can support this interface with multiple pages, the amount and complexity of the code to persist the data can become unwieldy as the user pages back and forth in the wizard. Using ASP.NET's Panel control can simplify this interface greatly.

Create a Panel for each step in the wizard and one set of Cancel, Next, Back, and Save buttons on the form. Inside the Panel control are the user-interface elements needed to support the particular step of the wizard.

In the event handler for each of the command buttons is the code to hide and unhide the correct panels and buttons based on the state of the wizard. At the end of the wizard, the event handler for the Save button will commit the data. Because all the steps of the wizard are in panels on the one page, the event handler has access to all the data of the various steps. The user will believe each step is generating a new page based on the state of the wizard, but the developer has an easier time and less code.

The bottom line

As you can see, building a rich and responsive user interface is easy and beneficial with ASP.NET. By using a combination of basic and advanced tips, you can deliver client-server functionality with the deployment benefits of browser-based applications. Whether you are writing applications for Internet or intranet use, ASP.NET provides a robust platform for writing incredible and responsive interfaces.

Brad McCabe is the technical evangelist for Infragistics. Brad also has been a systems architect and consultant for Verizon Communications and many other clients, and he was a leading .NET evangelist within Ajilon Consulting. His primary interests include ASP.NET, Windows CE .NET, .NET Compact Framework, and Microsoft's networking technologies. E-mail him at brad@infragistics.com.

This article was provided by asp.netPRO Magazine, an online information resource for the ASP.NET developer community, which helps professional software developers build, deploy and run the next generation of dynamic, distributed Web applications quickly and easily. Click here for subscription information.

0 comments

E-Mail

Username / Password

Password

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy