Subclass web controls?

B

Big

I am new to web control creation. Is there a way I can
subclass a web control? For example, can I write the
following C# class definition:

public class MyImageButton :
System.Web.UI.WebControls.ImageButton
{
.......
}

Will this work like typical implementation inheritance
would?

Thanks,
Big
 
S

Scott Wisniewski

Yes.
Web controls are classes just like any other .NET class.
What makes a WebControl a web control is that it derives from the
System.Web.UI.Control class.
The Control class defines the basic protocol for a control to interact with
a page in the ASP.NET framework.
By deriving from an existing control and overriding its methods you can
modify how that control interacts with the framework, thereby changing its
behavior and or appearance. Most of its methods are virtual, which offers a
great deal of flexibility: almost any aspect of the control can be modified
by a derived class. One of the easiest ways to start writing custom web
controls is via composition, as it offers a gentle introduction to the
ASP.NET server control framework and a shallow learning curve. To get
started, lookup the CreateChildControls method of the control class.
 
G

Guest

Thanks Scott. I do appreciate your response very much.
Someone once told me you cannot subclass a DataGrid,
therefore, I was under the assumption that you could not
subclass web controls. I should have known better!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,219
Latest member
Geraldine7

Latest Threads

Top