Jake Petroules
Jake Petroules

Reputation: 24150

Best way to add a formatted localized string to an ASP.NET page?

I've been using <asp:Literal runat="server" meta:resourcekey="Blah" /> with resx files in the App_LocalResources directory for translatable strings, but if my key, Blah.Text is "Enter the {0} category", how would I pass the parameter to replace {0} in this context?

I know I could use <%=string.Format(... but that seems unclean and I can't access the Local Resources in that way. What should I do for this use case?

Upvotes: 2

Views: 2205

Answers (1)

Oleks
Oleks

Reputation: 32323

An example of markup:

<asp:Literal runat="server" ID="Blah" />

from the code behind:

Blah.Text = string.Format(
    "Enter the {0} category", 
    GetLocalResourceObject("Blah").ToString()
);

by using GetLocalResourceObject method.

Upvotes: 4

Related Questions