views:

623

answers:

3

Hi.

I haven't been able to figure out how to use strings from resource files (resx) in SharePoint master pages.

I know how to use it with server controls, but can I somehow extract a value and use it in generalt html. I.e. in an alt attribute on a img tag?

<img src="photo.jpg" alt="my_resource_entry_here" />
A: 

I assume you have a class with a method that lets you get the resource string by the key, e.g. MyResources.GetString(key). In that case you can use something like this:

<img src="photo.jpg" alt='<%=MyResources.GetString("my_resource_key_here")%>' />
boredgeek
This approach does not seem to work. I've tried with the following error as result:An error occurred during the processing of /_catalogs/masterpage/x.master. Code blocks are not allowed in this file.
Peter Lindholm
A: 

The easiest way would be to add a runat="server" attribute to your alt tag. That will solve your problem and you can use the "normal" way of getting resources. Othwerwise use this syntax to get value from the resx files places in App_Global resources:

    <img src="photo.jpg" 
alt='<%=this.GetGlobalResourceObject("Global", "Mystring").ToString()%>'
Johan Leino