ASP.NET Custom Server Controls: Breaking the Secrets of Rendering
(Page 1 of 5 )
If you are confused about the rendering methodologies of a custom control in ASP.NET, you can simply master it from all of the secrets I introduce in this article.
In my previous article, I already introduced you to creating your own TextBox control with cool features, without even deriving it from an existing ASP.NET TextBox control. I concentrated only on getting out my own TextBox, and not much on rendering. This article should give you insightful information about the rendering methodologies available in ASP.NET custom control development.
“Control” and “WebControl” class
To develop any custom control we generally design a class which gets derived from either of the following two classes:
- System.Web.UI.Control
- System.Web.UI.WebControls.WebControl
The System.Web.UI.Control provides only the basic functionality to make our custom control participate in the page frame work. The System.Web.UI.WebControls.WebControl is already derived from the System.Web.UI.Control class and provides support for additional properties such as font, height, width, and so on.
The rendering methodology between both classes is quite different from several aspects. But, one should note that both of them have the “render” method implemented internally (of course we can override them when necessary). But the lifecycle of a custom control depends upon the derivation from its parent class (either of “Control” or “WebControl” classes). This is where a control developer can get confused.
First of all, we need to decide which parent class is necessary for our custom control to be derived from. We need to make sure that we can even achieve the same output when dealing with any of those two parent classes. But, here the idea is to find the additional freebies we can get from the “WebControl” class.
If our custom control needs to implement all the types of common features like width, height, font, backcolor, forecolor, and so on, it is better to work with “WebControl.” If we want to take complete control over your custom control (including the normal features of the “WebControl” class), we need to consider the “Control” class. Once your custom control gets derived from the “Control” class, none of the features of the “WebControl” class will be available to you. You need to implement all of them by yourself.
These two classes are quite different from each other when rendering their lifecycles. Let us now go the secrets of rendering from both “Control” and “WebControl” classes.
Next: Secrets of “Control” class rendering >>
More ASP.NET Articles
More By Jagadish Chaterjee