Using Resource Strings in Web Part Layout

Alistair DeJonge asked on February 21, 2018 17:02

I'm trying to use a resource string I have created named lblLitCenterHeader (inside the Localization App in the the CMS backend) inside a custom layout of a web part

I have used:

<cms:LocalizedLabel ID="lblLitCenterHeader" resourcekey="lblLitCenterHeader" runat="server" />
<asp:Label ID="lblLitCenterHeader" resourcekey="lblLitCenterHeader" runat="server" />
<cms:LocalizedLabel ID="lblLitCenterHeader" runat="server" />
<%# Localize("Text containing localization expressions: {$lblLitCenterHeader$}") %>

None of them have worked. They either do not show or cause an error.

Please help

Correct Answer

Brenden Kehren answered on February 21, 2018 17:28

You need to know the difference between binding and non-binding code.

<%# MethodName() %> - is code used within a binding control like a repeater item.
<%= MethodName() %> - is code used within a non-binding control like a page template or page in general.

So you'd want to use <%= ResHelper.GetString("stringkey") %> in your asxc code.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on February 21, 2018 17:11

The method Localize() only works in transformations. You need to use ResHelper.GetString("stringKey")

Secondly, when you want to set the text for a label, use lblLitCenterHeader.Text = GetString("stringKey");

0 votesVote for this answer Mark as a Correct answer

Alistair DeJonge answered on February 21, 2018 17:24

Ok, so do I put:

<%# ResHelper.GetString("lblLitCenterHeader") %>

Because that is not working.

0 votesVote for this answer Mark as a Correct answer

Alistair DeJonge answered on February 21, 2018 17:35

Ok, I swear I tried that as well, but tried again and it worked. Thank you.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.