Comments
Patrick Collands wrote: collands (AT) gmail com I'd be very grateful for an invitation. Thank you.
Cloud Computing
Conference & Expo
November 2-4, 2009 NYC
Register Today and SAVE !..

SYS-CON.TV
Today's Top SOA Links


Bring Windows to the Web: Bringing Desktop Apps to Your Web Sites
As .NET 2.0 approaches, which new technologies are worth implementing?

Listing 2 shows an example user control. This control is a very simple login form that has some basic functions to recognize a valid login. You'll notice that it looks very similar to Listing 1, but there are a few key differences. Rather than a page declaration at the beginning of the document, the file has a control declaration. It also has an ascx extension rather than an aspx extension. Another important thing to notice is that there are no form tags. The form tags for the server controls should reside on the page that uses them, not within the server control.

In lines 3-5, there are three properties defined: BackColor, Username, and Password. These properties can be set when inserting the user control into an aspx page or they can be manipulated programmatically like any other object property. Lines 2-18 contain the VB.NET code used by the control, and lines 19-43 contain the UI elements and server controls. Line 19 uses the BackColor property to set the background color of the user control.

Listing 3 demonstrates how to implement the user control. On line 2, the register directive allows us to reference the user control with the prefix "Demo" and tag name "Login" and points to the ascx file that defines the user control. On line 8, the user control is instantiated. The user control tag looks very similar to a normal server control. It has a unique ID, contains the runat=server attribute, and assigns a value to the BackColor property.

This is just a simple example of how you can use user controls to package code for reuse. In addition to forms, you can also create user controls for menus, contact forms, or another element that appears repeatedly in your site.

Beyond user controls, custom controls can be created in VB.NET or C#. These custom controls are compiled classes rather than ascx documents. While these custom server controls can offer more functionality than user controls, they're a bit beyond the scope of this article.

Third-Party Server Controls
Many software companies that build .NET-compatible software also create custom server controls to incorporate into your site. This helps with quick integration of third-party applications. For example, Crystal Reports provides .NET server controls to dynamically display report data on your Internet or intranet site. At Ektron, we use server controls almost exclusively to display content and provide functionality through our Content Management Solutions.

These server controls are usually contained in compiled DLL files and can often be imported into the Visual Studio toolbox. Like the built-in server controls, these third-party server controls can also be customized, extended, or incorporated into your own user controls.

Using .NET to Organize Code
Poorly written code can cripple a project. Most Web programming languages seem to encourage spaghetti code and other bad habits. This makes it exceedingly difficult to update and improve the application. ASP.NET provides a few features that help improve coding practices and improve scalability and modularity.

Separating code from design elements is the most important step in eliminating spaghetti code. ASP.NET provides a great way of both separating code and improving performance through code-behinds and data binding. Code-behinds are compiled VB files that can contain all of the functionality for a page or series of pages, allowing developers to place all of the code in a Visual Basic file and all of the UI and design elements in the .aspx file.

Listing 4 and Listing 5 show the same example as Listing 1 as written with a code-behind. Listing 4 is the VB.NET code-behind file and Listing 5 is the aspx file that uses it. In Listing 4, there is a public class that contains instances of the three server controls and the two sub routines that were used in Listing 1.

Line 2 instructs the class to inherit the page class. The code-behind class now inherits all of the properties and methods of the built-in page class. Lines 4-6 instantiate the three server controls so that both the aspx page and the code-behind can access them. Lines 8-14 are the same sub routines from Listing 1. Next, the code-behind needs to be connected to the aspx page.

Listing 5 shows the aspx page that uses the code-behind in Listing 4. There are only two changes from Listing 1: the script has been removed and the page directive has been altered. The script is now contained in the code-behind. The page directive needs to point to the code-behind file and needs to inherit the class within it. Because the code-behind class inherited the page class, all of the methods and properties of the page class will still be available.

Adding Connectivity with Web Services
Web services offer some great potential for connecting your application to a wide array of other applications. They allow you to take advantage of a standardized data system (XML and SOAP) to communicate across different operating systems and devices. The .NET framework provides great support for exposing and consuming Web services.

There are a few ways that you can use Web services to improve your application. FedEx and many other shipping companies use Web services to allow applications to acquire up-to-date shipping quotes. The Web service receives a SOAP request and returns the shipping information in an easily readable XML response. This allows developers to quickly integrate accurate shipping data into their application.

Another method is to use Web services to communicate between different elements within an application. At Ektron, our main software solution is built in .NET, but many of our clients use ColdFusion, JSP, or PHP. Since Web services use a universal data format, the .NET back end can easily connect to the presentation layer elements, even if they're programmed in a different language. This universal data format also allows the Web service to be consumed by other devices such as cell phones and PDAs.

The Future of ASP.NET
With .NET 2.0 already in the final stages of beta release, it would be appropriate to think about features that will be offered in the updated .NET framework. In addition to a boatload of new server controls, .NET 2.0 offers two great new features to increase productivity and improve the user experience.

One of the coolest new features is support for event-based asynchronous programming. This allows the application to function without refreshing the browser. Like AJAX, .NET 2.0 will provide ways to both recognize events in the browser and query the Web server without refreshing the page. Needless to say, this is a big step towards creating Web applications that function more like desktop applications.

Another great new feature is master pages. Master pages serve as templates for your site. You can create a single file that contains the layout and design elements of the site and apply them to content pages. This helps maintain consistency across the site and makes development more efficient. It also makes it much easier to make design and layout changes across an entire site quickly.

Conclusion
The .NET framework and ASP.NET represent a huge step forward in Web programming. While a migration to .NET from ASP or another language might be difficult, the benefits are worth it for most projects. The object-oriented approach of ASP.NET will improve the scalability and flexibility of your Web applications, Web services provide unlimited connectivity with the wide array of new Internet-enabled devices, and .NET 2.0 will offer new features that will bring your Web applications one step closer to replicating desktop applications. The .NET framework represents the future of Microsoft's plans for application development and there's no better time to start leveraging it to empower your Web applications.

.  .  . 

The author extends thanks to Ian Muir, Ektron technical specialist, for his assistance with this article.

About Bill Rogers
Bill Rogers is founder and CEO of Ektron, Inc (www.ektron.com). Founded in 1998, Ektron has nearly 15,000 customer integrations worldwide.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE