I do not think that you can take User Control (for example, a .ascx file) and put it in a class library for sharing among different applications.
Instead, you need to write Custom Control . This is basically a class (one .cs file not related to ascx) that comes from Control (or the Control option), for example, you can get it from DropDownList if you want to create your own drop-down list box).
Differences: https://msdn.microsoft.com/en-us/library/aa651710(v=vs.71).aspx
There is another MSDN article here: https://msdn.microsoft.com/en-us/library/aa479318.aspx , which discusses how to create a user control from a user control if you do not feel very comfortable with the idea of this .
It describes the following steps:
- Write your user control as usual using Visual Studio Designer.
- Test it with a simple page before trying to expand it.
- Deploy the application to precompile it.
- Grab the user control assembly created during the deployment phase, and you are essentially done: you have your own control.
- Finally, use user control in other applications the same way you always use user controls.
If you want to have a set of controls and don't want to have a separate DLL for each, then you can use a decompiler such as Reflector to see what was created and just copy / paste it into your class library together controls.
Then you should be able to register tagPrefix and the namespace, as you have already shown: <add tagPrefix="Controls" namespace="Comp.UserWebControls.Controls" assembly="Comp.UserWebControls" />
and you must be ready to go.
If the user control was not particularly complex, then I probably wanted to read about the clean code of Custom Controls and try and just write it so that instead of trying to capture and decompile the DLL.
I think the reason you return null values is most likely related to the viewstate and page life cycle. This is always what I struggled with most of Webforms, especially with dynamically loaded controls, figuring out where in the life cycle you should load them. I seem to remember that if you added them dynamically to Page_Load , for example, they would always seem to work, but then values would never be saved through callbacks, but then Page_Init worked fine.
So, I would say - create a user control, one class file for the user control, get rid of any traces of .ascx , and you should be good to go.