Chapter 9. Building User Controls and Server Controls

for RuBoard

Chapter 9. Building User Controls and Server Controls

IN THIS CHAPTER

  • Working with User Controls in Web Forms Applications

  • Creating Server Controls

Many server-scripting environments, including ASP.old, made it difficult to reuse the code that composes Web-based user interfaces. The most common option for creating reusable code is the server-side include (SSI). With SSIs, you create an external file containing HTML and/or server script that can be referenced, or included, from any other file in your Web application.

SSIs are adequate and are supported on many types of server environments (including both ASP.old and ASP.NET) across different platforms. But the server-side include is a harsh mistress, quick to anger. One problem is that the SSI doesn't provide any standard functionality, only a way for including code functionality from an external file. That means that the way you get access to code in a given SSI may be totally different from the way you access code in another. Also, code in SSIs typically is not accessible from any language (the language of the SSI must be the language of your main page), and making a change in an SSI that's referenced from multiple files frequently causes code in linked files to break.

This paucity of options for code reuse is in stark contrast to development environments such as Visual Basic and Java, which both have a rich library of user-interface controls that developers can access in the form of reusable objects. (In general, presenting code in the form of objects ensures that the code is consistent and easy to understand; it also keeps the developer who uses the code from having to know much of anything about how the code works internally.)

ASP.NET adds support for several new kinds of reusable user-interface objects (including server controls and HTML controls), all of which were introduced in earlier chapters. This chapter discusses how to create your own user-interface objects.

ASP.NET enables you to create two types of custom user-interface objects in Web forms programming:

  • User control ”This control is an evolution of the functionality traditionally provided by server-side includes. With user controls, you can easily create a bit of user-interface functionality that is based in easily maintained script. But unlike SSIs, Web forms user controls are fully object oriented, supporting properties, methods , and events.

  • Custom server control ”This control is a type of .NET component that also provides Web forms user-interface functionality, but in a way that takes advantage of the full spectrum of programmability features available in the .NET component development model. These features include inheritance of .NET UI component base classes, a powerful complexity-management tactic that prevents you from having to reinvent the wheel when creating custom components .

We discuss how to create both types of controls in this chapter. Because user controls are far easier to develop and are probably more commonly encountered , we'll cover those first.

for RuBoard


C# Developer[ap]s Guide to ASP. NET, XML, and ADO. NET
C# Developer[ap]s Guide to ASP. NET, XML, and ADO. NET
ISBN: 672321556
EAN: N/A
Year: 2005
Pages: 103

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