0

I want to set Resource key to the below href of anchor tag and used below two approaches.

<a href='<%$ Resources:Resource, NewsletterArchive %>' class="button action blue"> </a>

AND

<a href='<%=CommunityServer.Web.ResourceLibrary.Resource.NewsletterArchive %>' class="button action blue"> </a>

But, no luck.. Got the below error

>  Literal expressions like '<%$ Resources:Resource, NewsletterArchive
> %>' are not allowed. Use <asp:Literal runat="server" Text="<%$
> Resources:Resource, NewsletterArchive%>" /> instead.

Please, help.

2 Answers 2

2

Not sure if this helps, but this worked for me:

<a href="<asp:Literal runat="server" Text="<%$Resources:Branding, footerAboutLink%>" />">
<asp:Label ID="footerAbout" runat="server" Text="<%$Resources:Branding, footerAbout%>"></asp:Label></a>
2
  • this worked great! Thanks for providing a working sample. For anyone else using this approach...the name 'Branding' in the example would be the name of the resource file within the App_GlobalResources folder in your project. The complete file name is actually 'Branding.resx' which provides default context, in my case 'en-US'. To localize to Spanish create another file in the same folder named 'Branding.es.resx'. The value 'footerAboutLink' is the 'Name' within the resource file with a value you wish to see in the alt, title or in this case the url tag. Feb 4, 2020 at 17:30
  • this worked for me. thaks. Mar 7 at 8:30
0

Your first approach should work correctly. But if it is not working, you may use code behind.

Your design page:

<a id="hprLink" runat="server" class="button action blue">It is my link</a>

Your code behind:

hprLink.Attributes.Add("href", GetGlobalResourceObject("your_resource_file", "your_resource_key").ToString());
4
  • <a href="<%GetGlobalResourceObject("your_resource_file", "your_resource_key").ToString() %>" class="button action blue">It is my link</a> try out this approach
    – Khazratbek
    Dec 2, 2015 at 8:20
  • tried but gets an err System.NullReferenceException: Object reference not set to an instance of an object.
    – user5426326
    Dec 2, 2015 at 8:38
  • @PranavBilurkar have you appointed your resource file name and key correctly?
    – Khazratbek
    Dec 2, 2015 at 8:39
  • <a href="<%GetGlobalResourceObject("Resource", "Pets").ToString();%>" runat="server" class="button action blue" runat="server" id="href"><span class="label"><%=CommunityServer.Web.ResourceLibrary.Resource.NewsletterArchive %></span> </a> @khazratbek
    – user5426326
    Dec 2, 2015 at 8:42

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.