Answered by:
Error when trying to load a user control dynamically

Question
-
User2068649013 posted
I'm trying to load an embedded user control.
The user control is embedded to a .dll. Following code is used to load the control.
UserControl myCurrentControl = (UserControl)LoadControl(@"~/MyControls/CustomControls.dll/MyCustomControl.ascx");
The issue is this same code working when the project was a Web Site, now I have converted it to a Web Application and this gives the error file cannot be found?
Am I still referring to the correct location or in Web Apps do I have to load the dll from a different location?
Please help.
Friday, June 8, 2012 8:13 AM
Answers
-
User2068649013 posted
Thanks for the replies, I found what went wrong. This user control is embedded to the dll by setting it's property Build Action to Embedded Resource.
The problem was with my virtual path provider. I had to register the virtual path provider in "Application_Start" method in Global.asax. In my working web site it was done in AssemblyResourceProvider in App_Code. When converting Web site to Web App since theres no App_Code in web app this whole code was missing.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 11, 2012 2:20 AM
All replies
-
User-1423995609 posted
If it's in dll, you can just instantiate the instance of UserControl
UserControl myCurrentControl = new MyCustomControl();
Friday, June 8, 2012 8:22 AM -
User3866881 posted
If it's in dll, you can just instantiate the instance of UserControl
UserControl myCurrentControl = new MyCustomControl();
Agree!
My addition is that you should refer the dll into your proj before you wanna use that……
Reguards!
Saturday, June 9, 2012 8:37 PM -
User2068649013 posted
Thanks for the replies, I found what went wrong. This user control is embedded to the dll by setting it's property Build Action to Embedded Resource.
The problem was with my virtual path provider. I had to register the virtual path provider in "Application_Start" method in Global.asax. In my working web site it was done in AssemblyResourceProvider in App_Code. When converting Web site to Web App since theres no App_Code in web app this whole code was missing.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 11, 2012 2:20 AM