简体   繁体   中英

How to set resource key to anchor HREF tag on aspx page in asp.net localization

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.

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());

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM