开发者

C# - How to read string value from the custom resource provider?

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开发者_如何学Go 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");

Taken From MSDN Example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜