DotNetNuke, ASP.NET, Web Development Blog

When you Dynamically Load a Control, you must explicitly set the LocalResourceFile

This is something I've learned and forgotten at least 4 times. Writing these types of things here helps me remember and seem to help quite a few other people as well. So...

Usually in DotNetNuke, if you want to associate a resource file with your control, you just create a resource file with the same name as the ascx file plus the .resx extension and place it in your App_LocalResources directory. DotNetNuke and/or ASP.NET auto-magically associates the file with your code and it just works.

However, every time that I create a control that dynamically loads other controls, I spend 30 minutes looking at names and file placement and... trying to figure out why the resource file doesn't seem to be loading. Eventually, it comes to me, for dynamically loaded files, you must explicitly set the LocalResource file.

To do this add the following line to your PageLoad function in your dynamically loaded control:

 LocalResourceFile = DotNetNuke.Services.Localization.Localization.GetResourceFile(this, "controlfilename.ascx");

To learn more about DNN Module Localization, check out the DotNetNuke Module Localization Guide.

Comments

Leave a Comment
Gravatar
Name:
Email: (not displayed)
Comments:

CAPTCHA image
Enter the code shown above:
Website

Return to previous page