How do I build a control without an .ascx file, only with a DLL?

  • Thread starter Thread starter Alan Silver
  • Start date Start date
A

Alan Silver

Hello,

I would like to build a control that outputs some text. Due to the
simple nature of the output, if I did it with an .ascx file and a
code-behind, the .ascx would only contain a Literal control and nothing
else.

It seems that it would be much neater if I could do away with the .ascx
file and have the control totally contained within a DLL. I am sure this
isn't hard, but I can't work out how to write the code.

Any help would be appreciated. TIA
 
What you want is a custom web control, which is essentially a class
that inherits a asp.net web control. eg. TextBox

class MyTextBox : TextBox
{

}
 
It sounds like you want to create a custom control instead of a user

Thanks Steve. Your article went into some details about user controls,
but then just said that custom controls are different, without showing
an example code.

However, armed with the knowledge that I was wanting a custom control, I
did a quick search and found loads of articles explaining how to do it.
It's quite easy really!!

Thanks again
 
Actually Steve's stite has alot of sample code for custom controls.
Remember, he's considered the 'Control Freak' :)
 
Actually Steve's stite has alot of sample code for custom controls.
Remember, he's considered the 'Control Freak' :)

I know, I was referring to that one article, which didn't have any code
for custom controls, nor links to sample code.

I wasn't criticising, merely passing comment. I have used his site many
times ;-)
 
See http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx on
one approach using 2.0. You can now re-use user controls as dlls.

Thanks, that's a useful link. As it happens, the control in question was
really simple anyway as far as the UI was concerned, so it was very easy
to do as a custom control once I knew the basics (which took about five
seconds to learn once I knew it was called a custom control!!). The
control just generated plain text, so I inherited it from Control and
overrode the Render method.

Having said that, I have some other controls that would benefit greatly
from this tip. Thanks again.
 
Back
Top