|
Comments
|
Today's Top SOA Links
ASP.NET Bring Windows to the Web: Bringing Desktop Apps to Your Web Sites
As .NET 2.0 approaches, which new technologies are worth implementing?
By: Bill Rogers
Oct. 3, 2005 02:30 AM
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 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 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 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 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 author extends thanks to Ian Muir, Ektron technical specialist, for his assistance with this article. 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!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||