If I have a page called Default.aspx, ASP.NET automatically uses the resource file named Default.aspx.resx in App_LocalResources for localizing server controls in the page.
But for some reason, I need to choose another file, let’s say Default-Custom.aspx.resx. To provide some background, I already have Default.aspx.resx but some users need to have different content shown to them, which I am going to put in Default-Custom.aspx.resx.
Is is possible to choose the Resource file used for a TemplateControl in ASP.NET (short of writing a custom ResourceProvider)??
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Take a look here:
ResourceManager.GetResourceFileName Method
This method uses CultureInfo ‘s Name
property as part of the file name for
all cultures other than the invariant
culture. This method does not look in
an assembly’s manifest or touch the
disk, and is used only to construct
what a resource file name (suitable
for passing to the ResourceReader
constructor) or a manifest resource
blob name should be.A derived class can override this
method to look for a different
extension, such as “.ResX”, or a
completely different scheme for naming
files.
You can try something like this:
public class ResxResourceManager : ResourceManager
{
protected override string GetResourceFileName(
System.Globalization.CultureInfo culture)
{
return base.GetResourceFileName(culture);
}
public string GetResxFileName(System.Globalization.CultureInfo culture)
{
return GetResourceFileName(culture).Replace(".resources", ".resx");
}
}
For more on this:
Creating a custom Resource Provider
Under the Hood of BuildManager and Resource Handling
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0