Is there a way to translate a path to a user control, ~/usercontrols/MyUserControl.ascx, to a type, as in typeof(MyUserControl)?
Asked
Active
Viewed 909 times
1 Answers
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
-
1Is 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