Jak*_*ade 14 c# asp.net resources
如何在没有ASP.NET控件的情况下显示资源的值,即我想避免这种情况:
<asp:Label text="<%$ Resources: Messages, ThankYouLabel %>" id="label1" runat="server" />
Run Code Online (Sandbox Code Playgroud)
相反,我更愿意在我的.aspx页面中这样做:
<%$ Resources: Messages, ThankYouLabel %>
Run Code Online (Sandbox Code Playgroud)
...但我不能,抛出一个解析器错误:
Literal expressions like '<%$ Resources: Messages, ThankYouLabel %>' are not allowed.
Use <asp:Literal runat="server" Text="<%$ Resources: Messages, ThankYouLabel %>" /> instead.
Run Code Online (Sandbox Code Playgroud)
Ale*_*lex 21
改为使用HttpContext.GetGlobalResourceObject:
<asp:Label text='<%= GetGlobalResourceObject("Messages", "ThankYouLabel") %>'
id="label1"
runat="server" />
Run Code Online (Sandbox Code Playgroud)
这是不可能的.你必须使用atleast Literal,另一种选择是使用GetGlobalResurceObject,这样你就可以直接在页面中使用.
<%= GetGlobalResourceObject("Messages", "ThankYouLabel")%>
Run Code Online (Sandbox Code Playgroud)