Instantiate a web user control in a class in app_code
I am writing a class called Evaluatieform that works with web user controls, their events and eventually adds them to a panel so the web page only needs to instantiate the Evaluatieform class and call a method that returns the panel so it can show it on the website. Now the problem is that I can't instantiate my us开发者_C百科er controls I have defined.
First error : The type or namespace name 'DomeinsCriteriums' could not be found(are you missing a using directive or an assembly reference?)
So the next thing I try is to drag the user controls needed into the app_code folder. This however, does not work because the compiler does not allow a web user control in that folder.
I read somewhere else to use ASP.webusercontrol_ascx usercontrol = new ASP.DomeinsCriteriums_ascx(); However, this does not work aswell.
Can anybody give me a quick solution for this problem?
All you need to do to load a user control is this.
Control ItemX = (Control)Page.LoadControl("/controls/yourusercontrol.ascx");
However if you are getting a namespace error. Simply add the namespace to the top of your page.
using DomeinsCriteriums;
精彩评论