Home > Articles > Programming > ASP .NET

ASP.NET Rendered Custom Controls with C#Builder

  • Print
  • + Share This
Of the three types of ASP.NET controls, a rendered custom control is the most powerful. Rendered custom controls give you the ability to manipulate the appearance and behavior of a control at a very fine-grained level. Although rendered custom controls are somewhat complex to use, the advantage is that you have full control over their appearance, events, and state.
Like this article? We recommend

Like this article? We recommend

C#Builder has wizards to help you get started building rendered custom controls. Rendered custom controls require you to implement more code and perform manual operations, which is different from other types of controls that rely on their constituent controls to perform these tasks. This article explains how to do control drawing and perform these extra operations so you can begin creating your own rendered custom controls.


Here's the source code for this article.

Getting Started with Rendered Custom Controls

To get started with creating a new rendered custom control project, press Ctrl+N and open the Web Control Library wizard under the C# ASP Projects folder.


If you aren't yet familiar with working in C#Builder, see my previous article "Building ASP.NET Applications with C#Builder for Microsoft .NET" for details. Many of the tasks required to work with rendered custom controls are the same as those for composite custom controls; for more information on composite custom controls, see my previous article "Events and Properties for Composite Custom Controls in C#Builder."

The control we're going to build is a rating control that visitors to a site can use to rate a given page. It will have a set of options numbered 1 to 5 that the user can select to rate the page. When setting up this project, name the project and main file RatingControl. Along the same lines, modify the code template that was generated by the wizard to reflect the purpose of the control, as shown in Listing 1:

Listing 1 Class Declaration for RatingControl

namespace Mayo.Web.Controls
  /// <summary>
  /// Lets users rate web pages.
  /// </summary>
"<{0}:RatingControl runat=server></{0}:RatingControl>")]
  public class RatingControl :
    // remaining code elided for clarity

The code in Listing 1 reflects the changes I made to place this control in the right namespace (Mayo.Web.Controls) and to name the control appropriately (RatingControl). I also modified the ToolboxData attribute so the RatingControl would appear properly on the web page when users drag it from the Tool Palette onto the design surface.

RatingControl also implements IPostBackDataHandler and IPostBackEventHandler. Both of these interfaces are explained and their members are implemented in subsequent sections of this article.

  • + Share This
  • 🔖 Save To Your Account