Last post Apr 11, 2014 02:24 AM by Pragati Katiyar
Mar 27, 2014 02:10 AM|MarlboroMan_wykyu|LINK
I have two Resource files under the app_GlobalResources folder in my Website project, (CaptionsA.resx and CaptionsB.resx), for CustomerA and CustomerB,respectively.
For example, in CaptionsA.resx I have,
MyButtonText ------> Click me!
And in CaptionsB.resx I have,
MyButtonText ------> Click Here
I have to use captions on multiple pages in my Website. But, when CustomerA uses the website all the captions from CaptionsA.resx should be visible and when CustomerB uses the website all the captions from CaptionsB.resx should be visible. Keep in mind that
both customers use English as the website language, So I can't use the culture/language localization thingy.
What I want to ask is, How to programmatically tell my website which Resource file to use when? What to write in my VB.net code? How to access the Resource File in my code?
If CustomerType = CustomerA
//RETRIEVE DATA FROM CaptionsA.resx (How to do this?)
else If CustomerType = CustomerB
//RETRIEVE DATA FROM CaptionsB.resx (How to do this?)
And what shall I write in the aspx source file?
<asp:Label ID="LblButtonText" runat="server" Text="<%$ Resources:WHAT-TO-WRITE-HERE?,MyButtonText %>"></asp:Label>
I've been Googling a lot and have tried to find teh answer on a gazillion forums, but threads related to this topic were mostly unanswered or were not helpful.
Mar 28, 2014 05:24 AM|rstrahl|LINK
For code based access you'll want to use:
string text = HttpContext.GetGlobalResourceObject("CaptionsA","ResourceId") as string;
string text2 = HttpContext.GetGlobalResourceObject("CaptionsB","ResourceId") as string;
If you're inside of a WebForm, the Page class also has this method so you can write it out without the HttpContext:
// Inside of WebForms Page this works too
string text3 = GetGlobalResourceObject("CaptionsA","ResourceId") as string;
You specify the ResourceSet which is the name of the ResX file and the ID of the value you're trying to look up.
Inside of ASP.NET WebForms controls you can use resources expressions:
<asp:Label ID="Label1" runat="server" Text="<%$ Resources:CompanyA,ResourceKey %>"></asp:Label>
Frankly though I think it'd be cleaner to just use:
<%= GetGlobalResourceObject("CaptionsA","ResourceId") %>
Here's an article I wrote many years ago on this topic on Localization:
Hope this helps,
+++ Rick ---
Apr 11, 2014 02:24 AM|Pragati Katiyar|LINK
Resource file should not refer the customer where as it should refer the culture of that customer.