Prev | Current Page 86 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

NET, we first cover a couple of key concepts:
inheritance and encapsulation.
Inheritance
One way to package new functionality and take advantage of the rich, object-oriented framework
in ASP.NET is to use inheritance. This elegant, tried-and-true technique is the central
theme of this book and the topic on which we spend the most time.
Inheritance works because of the polymorphic behavior of objects. This capability permits
you to override methods defined as virtual in the base object class so that you can add or
customize the objects??™ behavior, with the option of still leveraging the functionality available in
the original base class method. To put it another way, you don??™t have to reinvent the wheel to
add new functionality. In terms of code, this will generally look something like the following:
//overide virtual method "Render"
protected override void Render(HtmlTextWriter output)
{
//add some new style to output
output.AddStyleAttribute("somestylename","somevalue");
base.Render(output); //render the output using the base class Render method
}
In this code snippet, we override the virtual method Render(), which is defined in the base
class System.Web.UI.Control. This syntax may look a little strange at first.


Pages:
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98