简体   繁体   中英

How can I access a UserControl from inside a class in App_code?

In a ASP.net Website project, I have a class in App_code folder called "abc" and have user control in a folder on root MyControl/Menu.ascx.

Now my question is how can I create an instance of my UserControl inside my "abc" class? because UserControl is not accessible.

像这样尝试

CustomControl cc = (CustomControl)Page.LoadControl("...");
  1. Include proper namespace of your user control

    using YourNamespace;

  2. Then Create Instance of uer control

    UserControlClass userconrtolinstance = new UserControlClass();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM