Last post Aug 11, 2008 10:23 AM by paudirac
Jul 16, 2008 05:45 AM|paudirac|LINK
I've been developing some business objects to use with an ObjectDataSource and some custom controls. Business objets' properties have some custom attributes that describe the type of field, it it's required, some masks, and other properties which will allow
me to automatically set some client-side behaviors and some server-side properties (such as styles) for the control. I'm trying (without success) to acess the object's at design time from my custom controls.
With a custom DataBindingHandler attached I can access the field name the custom control is bound to, and I can recursively find the ObjectDataSource control in the page. Then I can get the ObjectDataSource.TypeName, but I'm not able to intantiate the Type
at design-time. I've tried with Activator.CreateInstance which doesn't work and with the BuildManager.
I think the problem could be related with the fact that I'm not able to find the assembly the business objects reside on (which is in a WebSite solution, and my custom controls are in a library of components this web site uses), but maybe the problem is
in my approach. Any suggestions?
Any help would be much appreciated.
Aug 11, 2008 10:23 AM|paudirac|LINK
Well, finally I was able to solve the problem myself. Thanks for the feedback. It's easy once you know where to look. ;)
To anyone interested, you can put code inside the special ASP.NET folder App_Code and then edit the web.config and add something similar to
<add directoryname="mydirecotry" />
With this, you can access the run-time/design-time dll with the System.Web.Configuration.CompilationSection. You can load the assembly using something like:
System.Web.Configuration.CompilationSection section = (System.Web.Configuration.CompilationSection)System.Web.Configuration.WebConfigurationManager.GetSection("system.web/compilation");
string assemblyName = "App_SubCode_" + section.CodeSubDirectories.DirectoryName;
System.Reflection.Assembly asm = Assembly.Load(assemblyName);