Last post Dec 06, 2012 03:04 AM by dev_2580
Dec 06, 2012 01:42 AM|Curiouspo|LINK
I am writing a Web Application in asp.net 4.0. I have a Solution say ControlLib, where a have my User Control UC_A. I have another Solution say MainLib, which contain a User Control UC_B. I have added the .ascx,.dll and pdb file of my ControlLib to my MainLib.
Now a have to use UC_A in UC_B. Please tell me how can i achieve this.
Thanks in Advance
Dec 06, 2012 03:04 AM|dev_2580|LINK
My first option if this user control will be reused a lot is definitely to create a "Custom Control" rather than a user control. A custom control would allow you to simply reference you dll and the control is available for use in the project.
If however you don't want to go that route, since it is more difficult and time consuming you can reference a user control. Build ControlLib, copy the dll and .ascx over (as you have done), then reference the .ascx as if you would if it were part of your
MainLib solution! It does work, I've done it before.
Just incase you weren't awere of this, the reason you need the .ascx as well is that when you compile you assembly, a User Control's markup does not come along in the assembly, but only the code behind (your class). So if you view your assembly in Object
Browser, you see that your user control's class is there, but it has no markup / front end, so if you referenced it, you would get a NullReferenceException for any instances to controls on your user control.
<%@ Register Src="~/Uc_A.ascx" TagName="Uc_A" TagPrefix="cc" %>
<cc:Uc_A ID="MyUc" runat="server"></cc:Uc_A>
Check the following, might help you figure out what's wrong:
Hope this helps