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

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
 
T

tdavisjr

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
{

}
 
A

Alan Silver

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
 
T

tdavisjr

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

Alan Silver

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 ;-)
 
A

Alan Silver

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.
 

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

Top