locked
Accessing User Control in App_Code RRS feed

  • Question

  • User-1245426334 posted

    Hi!

    Our CMS comes with plenty of built-in User Controls, which can be rather helpful.

    I was wondering if there's a way to create an instance of a User Control in a class inside my App_Code folder.

    I think I know the answer, but wanted to be sure. If memory serves, the App_Code folder is compiled before the rest of the project files, which means it can't access the User Control outside of that folder.

    Is that correct?

    If so, are there any tips or tricks that might help short of recreating the control they already gave us inside a class file?

    Thanks!

    -Eric

    Tuesday, July 2, 2013 2:15 PM

Answers

  • User551462331 posted

    I'm not sure how to cast the Control returned from LoadControl to the proper type.

    normal casting will do... did u try this?

    CustomControl cc = (CustomControl)Page.LoadControl("...");

    hope this helps...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 3, 2013 12:21 AM

All replies

  • User551462331 posted

    do u want to simply create object of control class inside app_code class?

    u should be use loadcontrol to create user control object even from inside app_code...

    if u face issue, u can try moving user control file to app_code and change path in loadcontrol accordingly

    hope this helps...

    Tuesday, July 2, 2013 2:24 PM
  • User-1245426334 posted

    Thanks, KK.

    The issue then becomes accessing the Controls properties in my Class file.

    I'm not sure how to cast the Control returned from LoadControl to the proper type.

    Thanks!

    -Eric

    Tuesday, July 2, 2013 3:29 PM
  • User551462331 posted

    I'm not sure how to cast the Control returned from LoadControl to the proper type.

    normal casting will do... did u try this?

    CustomControl cc = (CustomControl)Page.LoadControl("...");

    hope this helps...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 3, 2013 12:21 AM