Creating A Custom HtmlControl

N

Nathan Sokalski

I want to create a custom control that has a style and id attribute, but not
all the extra stuff that a WebControl has. I would think I would inherit
from either the HtmlControl HtmlGenericControl class, but this does not seem
to be working. I have written lots of controls in the past by inheriting
from the Control and WebControl classes, so I have written custom control
before, and I have managed to make a working version of my control by
inheriting from the Control class, but I want to find a way to avoid all the
extra work to add the style and id attributes that I should be able to get
by inheriting from another class. Thanks.
 
G

Gregory A. Beamer

I want to create a custom control that has a style and id attribute,
but not all the extra stuff that a WebControl has. I would think I
would inherit from either the HtmlControl HtmlGenericControl class,
but this does not seem to be working. I have written lots of controls
in the past by inheriting from the Control and WebControl classes, so
I have written custom control before, and I have managed to make a
working version of my control by inheriting from the Control class,
but I want to find a way to avoid all the extra work to add the style
and id attributes that I should be able to get by inheriting from
another class. Thanks.

As it "costs" no more to create an ASP.NET Server control, I am not sure
why you want to jump through these hoops. Yes, you avoid the "extra"
stuff, but you can simply ignore it. you are not gaining a huge amount
of performance, if any, by going the more limited HTML route. And, if
you are going to market this control, you have greatly limited what can
be done with it.

That aside: As for a roadmap to doing it, try finding a similar control
already in the library and then use Reflector (free from RedGate) to
figure out what you have to include. To have this render properly, you
will have some attributes to set on the control. I would play with this
myself, but I see no use for it for my projects, at least not at
present.
 

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

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top