Custom Controls


ASP.NET defines an architecture for extending its existing controls with custom controls. You can write controls to encapsulate portions of your Web applications into truly reusable components by deriving from System.Web.UI.Control and overriding the virtual Render method. An instance of the HtmlTextWriter class is passed into Render and provides a collection of helper routines for generating HTML to the response buffer. Inside your control's Render implementation, you are free to query the capabilities of the current client and render your control's state differently for different browsers. You can also render client-side JavaScript to clients that support it as part of your control's rendering, shifting some work to the client where possible.

Developers of custom controls must be very aware of how the state of their control is managed. Control users expect controls to retain their state across post-backs, which typically means that a control must use the ViewState mechanism to save and restore its state. It is also possible to manually parse the contents of the POST body if your control's state is propagated that way.

Composite controls are controls that contain other controls as children and are often used to build pieces of a form. You create composite controls by overriding the virtual CreateChildControls method and implementing the tagging interface INamingContainer. Even more useful are user controls, which create composite control definitions from .ascx files, letting you lay out your composite control with a designer.

The last step in building a user-friendly control is to ensure that it integrates cleanly with the Visual Studio .NET designer. Controls can specify what their Toolbox bitmap should look like, how their tags should appear when placed on a page, how to edit their properties, and what the control should look like in design mode.

     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows