Custom Controls
So far, you have created user controls, which are essentially reusable web page fragments.[*] You can also create your own compiled custom controls . As noted earlier, there are three ways to create custom controls :
Create a derived custom control by deriving from an existing control.
Create a composite control by grouping existing controls together into a new control.
Create a full custom control by deriving from
System.Web.UI.WebControls.WebControl
.
The custom controls most similar to user controls are the composite controls. The key difference is that composite controls are compiled into a DLL and used as you would any server control you find in the Toolbox.
Creating a Web Control Library
To get started, you'll create a Web Control Library in which you'll place the various custom controls for this chapter. Open Visual Studio .NET and choose New Project. In the New Project Window, create a Web Control Library called CustomControls
, as shown in Figure 13-4.
After clicking OK, you'll notice that Visual Studio has created a complete custom control named WebCustomControl1
. Before examining this control, create a web application to test it. Right-click on the solution in the Solution explorer and choose Add â New Web Site. Set the name of your web site to CustomControlTester
. Your solution now includes two projects: a web site (with Default.aspx) and a Custom Controls library (with WebCustomControl1.vb).
Web Custom Control 1
Web Custom Control 1 is a full custom control, ...
Get Programming Visual Basic 2005 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.