Search code examples
globalizationresx

Is there a way to override a specific resource value in .NET .resx file?


So i have:

App_GlobalResources/MyApp.resx

with a Name/Value pair of "Email" = "Email Address"

In my application, is there a way to override this value? At some point in the application, I want to change the value of the Name/Value pair.

"Email" = "Email Address" ... becomes... "Email" = "Contact Email Address"

And have that referenced the same way, Resources.MyApp.Email.


Solution

  • Why not just make 2 entries in your resource file? One for "Contact Email Address" and one for "Email Address" and using your code decide which one to show under the circumstances.

    So if you are using Email Address as default you would have:

    <asp:Label ID="EmailAddressLabel" runat="server" meta:resourcekey="EmailAddressLabel"></asp:Label>
    

    And then to override that you would put something like this in your code behind:

    if (your logic here)
    {
         Email.Text = (String)GetLocalResourceObject ("ContactEmailAddressLabel");
    }
    

    The above is for local resource files. For Global you could use:

    Email.Text = (String)GetGlobalResourceObject("MyApp", "ContactEmailAddressLabel");
    

    and that would read the global resource key for you.