How to Consume a Custom Server Control

104 views Asked by At

I seem to be having a lot of trouble with this.

I want to create an ASP.NET control that implements some core logic, and then I want to be able to derive several controls from that, which each implement their own specialized logic.

I started with a User Control, but I couldn't find a way to derive from it. I tried setting the Inherits attribute in the derived control but, no matter what I did, the derived control just didn't seem able to recognize the base control.

So then I tried a custom server side control by using a regular class that inherits from Control. (Note that all my rendering is done from code.) But I can't seem to find any way to get a page to recognize the control. I've tried different syntax in the @Register directive but either it tells me the src attribute is missing or it just can't find the control. (Note that I prefer not to create a separate assembly if I don't have to.) I have no idea what to put as the assembly if the control is from the current assembly.

Can anyone make suggestions on this? Any examples that would work for my configuration, or perhaps a different approach entirely?

Note that I am not currently using page/control code-behind. All my page scripting is stored in the same file as my markup.

1

There are 1 answers

0
Jonathan Wood On BEST ANSWER

In fact, despite various error messages about missing attributes in the @Register directive, I found it works just fine if I reduce the number of attributes in this directive to just tagprefix and namespace.