Types of Controls You Can Create

 

Types of Controls You Can Create

All of the standard ASP.NET controls, such as TextBox, DropDownList, and Button , are standard server controls. For the end user of a control, standard server controls offer perhaps the best of all worlds. They can be easily dragged and dropped onto a form, and they offer a very rich design interface that allows the developer to visualize what the Web Form will look like when the page is run.

The design-time experience for your users is the good news about standard server controls. The bad news is that creating them is much more difficult than creating a standard ASP.NET Web Form. Rather than creating the control declaratively, and possibly adding some code where required, you must create standard server controls entirely in code. Testing standard server controls can be troublesome as well. Often, debugging standard server controls involves placing them on a page and examining the HTML source when the page is run.

An alternative type of custom control that you as a developer can create is called a user control. User controls are often seen as the ASP.NET answer to server-side includes that are used in Classic ASP. In Classic ASP, it was common to create reusable chunks of markup and code by creating include files, and then using the include directive on every page of the application that needed the chunk of markup and code that the include file contained. Server-side includes are supported by ASP.NET 2.0 for backward compatibility, but their use is discouraged, primarily because user controls offer a better alternative.

You program against properties of user controls. You can also easily use the same chunk of functionality more than once on a single page, and you can dynamically include any number of instances of the user control. In addition, ASP.NET 2.0 offers an improved design interface for user controls. In earlier versions, when you dragged a copy of a user control onto a page from Solution Explorer, only a gray box appeared to represent the user control. ASP.NET 2.0 displays the user control as it will appear when the page is run.

One specialized type of custom control remains: Web Parts. Recall from Chapter 4, "Working with Web Parts," that you can use any server control as a Web Part. But by either creating a custom Web Part or implementing an interface in a user control, you can also customize the look of the Web Part.

Which type of control is right for your application? The answer is, of course, "It depends." It depends on who will be using the control. It depends on the complexity of the user interface you are developing. And it depends on your ability as a developer. This chapter will introduce you to each type of control and help you decide which one is best for your specific application.

 


Programming Microsoft Web Forms
Programming Microsoft Web Forms (Pro Developer)
ISBN: 0735621799
EAN: 2147483647
Year: 2005
Pages: 70

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