M
mschep
Hi,
I built an assembly with a set of user controls.
This can be done with the Visual Studio 2005 Deployment Project:
building and merging for example all your aspx and ascx in one dll
(named BunchOfUserControls.dll)
Doing so it's possible to resuse user controls in other web projects
without transferring the ascx files. Just the dll.
'The reason I need this is because I need to load dynamicly controls in
a website.
This works fine.
The only thing to keep in mind is that it's not possible to use your
own class name.
Supose your user control is named MyNameSpace.MyUserControl the final
dll will contain a class named ASP.<name sub folder>_MyUserControl_ascx
This class is derived from my own class and overrides the
FrameworkInitialize method in order to render the ascx declarative
code.
<name sub folder> is the folder were I've got my user controls in the
original solution.
So creating the user control dynamicly you need to do the following:
Assembly assembly = Assembly.Load("BunchOfUserControls");
object instance =
portletAssembly.CreateInstance("ASP.mysubfolder_myusercontrol_ascx");
myPage.Controls.Add((Control)instance);
This works fine. The page shows correcly the user control.
And now my problem: I need to localize my controls. Just created resx
files for some languanges and user the same technique to create my
assemblies.
Web deployment project creates an assembly for the resources:
App_LocalResources.mysubfolder.cdcab7d2.dll
Running the system again it produces an error after adding my control
to the page: cannot find resouce file.
After inspecting the resource dll (with Reflector) I see all my user
controls, however the've got the original names (MyUserControl). The
user control dll (with Reflector) shows mysubfolder_myusercontrol_ascx.
So I guess there is a problem matching the two.
Is there somebody knowing how to solve this problem?
Kind regards,
Michel
I built an assembly with a set of user controls.
This can be done with the Visual Studio 2005 Deployment Project:
building and merging for example all your aspx and ascx in one dll
(named BunchOfUserControls.dll)
Doing so it's possible to resuse user controls in other web projects
without transferring the ascx files. Just the dll.
'The reason I need this is because I need to load dynamicly controls in
a website.
This works fine.
The only thing to keep in mind is that it's not possible to use your
own class name.
Supose your user control is named MyNameSpace.MyUserControl the final
dll will contain a class named ASP.<name sub folder>_MyUserControl_ascx
This class is derived from my own class and overrides the
FrameworkInitialize method in order to render the ascx declarative
code.
<name sub folder> is the folder were I've got my user controls in the
original solution.
So creating the user control dynamicly you need to do the following:
Assembly assembly = Assembly.Load("BunchOfUserControls");
object instance =
portletAssembly.CreateInstance("ASP.mysubfolder_myusercontrol_ascx");
myPage.Controls.Add((Control)instance);
This works fine. The page shows correcly the user control.
And now my problem: I need to localize my controls. Just created resx
files for some languanges and user the same technique to create my
assemblies.
Web deployment project creates an assembly for the resources:
App_LocalResources.mysubfolder.cdcab7d2.dll
Running the system again it produces an error after adding my control
to the page: cannot find resouce file.
After inspecting the resource dll (with Reflector) I see all my user
controls, however the've got the original names (MyUserControl). The
user control dll (with Reflector) shows mysubfolder_myusercontrol_ascx.
So I guess there is a problem matching the two.
Is there somebody knowing how to solve this problem?
Kind regards,
Michel