What Are User Controls?

   

User controls are an answer to prayers we have been secretly been petitioning the web gods about. Include files have always been a semi-answer to simple code reuse in web pages, but there are several inherent problems with include files that have been powerfully addressed by User controls.

User controls are essentially reusable blocks of code focused for user interface purposes. They are available to reuse as common components across your web application. They aren't magic or really any different than ASP.NET pages, except that they are created and formatted in a particular way so that they may be reused across your application.

As Clyde said earlier, SSIs (or Server Side Include files) partially filled this gap and provided the most flexible solution for providing reusable blocks of code before ASP.NET, but they really had huge problems (better stated as limitations) associated with them as well.

The biggest difference between the two is again the biggest difference between traditional ASP and ASP.NET. User controls operate under the same object-oriented paradigm and are treated as objects in your ASP.NET pages. These User controls can contain properties and methods just like any other object. They can be manipulated programmatically, just like other server controls in ASP.NET. You can even use code behind techniques in User controls to further separate UI function from logical programming.

Another annoying characteristic of include files is that all paths to images must be full paths. If you tried to insert images with document-relative paths, you would run into broken links if the file you were inserting the include file into didn't have the exact path to the images folder that the include file did.

Now it may not sound like a big deal to have to insert fully qualified paths using full protocol and domain name or IP address as well as file structure, but let me point out where the hassle begins. What if you do development on one system and move the site into production on another? In development you would have to have your full paths point to a local IP address such as http://192.168.1.100/images/image.gif, but when you were ready to go live into production all of these paths would need to be changed to replace the IP with your domain. Not only was this a big pain in the behind but it left tons of room for mishap and errors. Nothing like making sweeping changes to file paths just before you go live with a site without being able to test it thoroughly.

As I've said, User controls replace the function of SSIs and solve these problems, not by enhancing the function of SSIs, but by approaching it from a totally .NET point of view. ASP.NET does allow you to continue to use SSIs in the traditional sense, just as you have in the past, but after you are finished with this chapter 1 doubt you will see the point of that.


   
Top


ASP. NET for Web Designers
ASP.NET for Web Designers
ISBN: 073571262X
EAN: 2147483647
Year: 2005
Pages: 94
Authors: Peter Ladka

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net