Using RegisterClientScriptResource inside merged web control.

Mar 31, 2013 at 4:42 PM
Edited Mar 31, 2013 at 4:43 PM
Hi,
I trying to resolve one problem with dynamically loaded web control created with WebLibraryMaker.
Problem is when I load assembly data from database, create instance of object of my type, control renders correctly, but all scripts registered by RegisterClientScriptResource are not loaded because of 404 Not Found. WebResource.axd don't find Type, I think.

When I add library to my host project, and do the same steps as mentioned above, scripts are loaded correctly.

But I can not add libraries at buid time, because external controls will be created in future, today I must prepare my small runtime base for that functionality.

What I'm doing wrong?

Small part of my code where I dynamically create instance:
public static UserControl GetControl(Guid id)
        {
            UserControl pControl = null;
            DB_Plugins pConfig = null;
            Type pType = null;
            Assembly pAssembly = null;
            using (Plugins.PluginEntities context = new PluginEntities())
            {
                pConfig = (from prow in context.DB_Plugins
                           where prow.rowguid == id
                           select prow).FirstOrDefault();
            }
            pAssembly = Assembly.Load(pConfig.moduleData);
            if (!AppDomain.CurrentDomain.GetAssemblies().Contains(pAssembly))
                AppDomain.CurrentDomain.Load(pAssembly.FullName);
            pType = (from typ in pAssembly.GetTypes()
                                 where typ.Name == pConfig.moduleControl
                                 select typ).FirstOrDefault();
            pControl = (UserControl)Activator.CreateInstance(pType);
            return pControl;
        }
And inside external control:
ScriptManager.RegisterClientScriptResource((MYNS.Web.Plugins.Lib.PluginControl)this, typeof(MYNS.Web.Plugins.Controls.SampleControl.PluginLoader), "MYNS.Web.Plugins.Controls.SampleControl.base.js");