Using Resource Files in SharePoint MasterPages

I was unable to figure out how to use strings from resource files (resx) in master SharePoint pages.

I know how to use it with server controls, but can I somehow extract the value and use it in the generalt html. That is, in the alt attribute in the img tag?

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

      

0


a source to share


3 answers


The easiest way is to add the runat = "server" attribute to your alt tag. This will solve your problem and you can use the "normal" way to obtain resources. Othwerwise use this syntax to get value from resx file locations in App_Global resources:



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

      

0


a source


Here are 2 very good blog posts that describe how to use the resources:



+1


a source


I am assuming you have a class with a method that allows you to get a resource string using a key, eg. MyResources.GetString (key). In this case, you can use something like this:

<img src="photo.jpg" alt='<%=MyResources.GetString("my_resource_key_here")%>' />

      

0


a source







All Articles