Is it possible to have an space in a resource key and use it on ASPX page?
I have a resource that a key will have a space, like
My key | Some string
In my aspx page I want to call
<%$ Resource:Resources, My Key %>
Is there some syntax that allows me to use "My 开发者_如何学PythonKey" instead of "MyKey"?
No. The key for a resource setting may not contain spaces. Resource files are compiled so that the keys become variable names. This would be the equivalent of saying:
int My int;
This just is not allowed.
I take it back. Having applied some tests, this can be done and basically as you have described it. Some things that I see off the top is that in a web site, the resources file can't be in the App_GlobalResources
folder it needs to be in App_LocalResources
. I named my resources file the same as my page name like: Default.aspx.resx
. Resources in the App_GlobalResources
folder are set at internal scope automatically.
Inside it I had 2 keys and 2 values set:
ThisKey | ThisValue
My Key | My Value
To acess them from a control in the webpage I used a hyperlink control to test it:
<asp:HyperLink ID="hlLink" runat="server" Text='<%$ Resources: ThisKey%>'></asp:HyperLink>
Which output a link with the text ThisValue
. And also:
<asp:HyperLink ID="hlLink" runat="server" Text='<%$ Resources: My Key %>'></asp:HyperLink>
Which output a link with the text 'My Value'. I did notice that if I attempted to specify the "class" parameter by using Resources: Default.aspx, My Key
it bombed. It was only successful using the resources within the App_LocalResources
folder and only when specified to that file name.
I'm sure this isn't the only way to do this, but this method was successful in allowing a space in the key name for that page.
精彩评论