I created a custom resource provider by following guidelines from the following link: http://asp-net-whidbey.blogspot.com/2006/03/aspnet-20-custom-resource-provider.html
On .aspx pages I'm using the following code and it work fine:
<asp:Literal ID="ltlFoo" runat="server" Text="<%$ Resources:SomeText %>" />
Now I'd like to read the localized value from the code:
string foo = Resources.GetString("SomeText");
The problem is that I don't know how to instantiate the resource manager.
Any help would be greatly appreciated!
EDIT:
I used the following code and it works great:
string foo = (string)GetGlobalResourceObject("", "SomeText");
Is there any reason why I should not use that code?
So your resource manager should have a name and you should be able to do something similar to the following.
// Create a resource manager to retrieve resources.
ResourceManager rm = new ResourceManager("items",
Assembly.GetExecutingAssembly());
// Retrieve the value of the string resource named "welcome".
// The resource manager will retrieve the value of the
// localized resource using the caller's current culture setting.
String foo = rm.GetString("SomeText");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.