问题
I wrote an ASP.Net Program that use resource key to support multi language support
Now I want to tokenize this module to enable user give template to it.
for that I give tokens to user to drop it in module and I will replace it. for example if user type [lblsomething] in HTML I will replace it with
<span id="lblsomething"> something </span>
Now the problem is how can i use resource key with this span to support multi language just like what i have in ASP.Net <asp:label resourcekey="lblsomething"></asp:label>
Thanks a lot for any help you can provide
回答1:
you can try it in cs:
string something=Localization.GetString("KEY" , this.LocalResourceFile);
string html="<span id="lblsomething">"+something+"</span>"
and then add html string to page
回答2:
You neeed to add runat="server" to the control.
<span id="something" runat="server" meta:resourcekey="PressMeButtonResources"/>
Or alternatively, you can use literal control inside the span tag.
回答3:
Strangely the solution Localization.GetString... by atabrizi doens't work for me.
This works in my case (example for birthday label + textbox in a form):
<label for="birthday">
<%=GetLocalResourceObject("form_Birthday.Text").ToString()%>
</label>
<input type="text" id="birthday" name="birthday" />
msdn: How to: Retrieve Resource Values Programmatically
来源:https://stackoverflow.com/questions/9109315/can-i-use-resourcekey-in-html