1

Is there a way to translate a path to a user control, ~/usercontrols/MyUserControl.ascx, to a type, as in typeof(MyUserControl)?

Mr Bell
  • 9,228
  • 18
  • 84
  • 134

1 Answers1

0

Use the LoadControl() method on the Page class:

Loads a Control object from a file based on a specified virtual path. MSDN

LoadControl("MyUserControl.ascx").GetType()
Stefan
  • 14,530
  • 4
  • 55
  • 62
  • 1
    Is it possible to get the type without actually instantiating and instance? – Mr Bell Mar 05 '11 at 18:45
  • Give BuildManager.GetCompiledType(string virtualPath) a shot (http://msdn.microsoft.com/en-us/library/system.web.compilation.buildmanager.getcompiledtype.aspx). Since the use control will be compiled if it was not already a fear there are some security concerns ahead... – Stefan Mar 05 '11 at 19:06