Localization in form layout K10

bert limerkens asked on May 17, 2017 11:16

Hey guys

I'm currently upgrading my Kentico 9 project to Kentico 10. I got the site up and running and now I've noticed an error while testing the site.

In my form layout I have a title which I localized.

I get it like this:

<h2><%= CMS.Helpers.ResHelper.GetString("Title1") %></h2>

In Kentico 9 this worked like a charm. In Kentico 10 however I get this error

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

After looking into the documentation I saw the recommend doing it like this:

<%# Localize("Text containing localization expressions: {$stringKey$}") %>

This does not work at all. I get this error in the event log:

Message: http://server/CMSVirtualFiles/FormLayouts/=vg=7f17df12-039d-40b8-afef-231dd662cf02/BizForm.Form.ascx(7): error CS0118: 'System.Web.UI.WebControls.Localize' is a 'type' but is used like a 'variable'

Any idea how i can solve this?

Thanks in advance!

Greetings,

Bert

Correct Answer

Prashant Verma answered on May 17, 2017 12:11

Hi Bert,

Solution 1

I also faced same issue when upgrading it from v9.0 to v10.0 their are some defect's in 10.0.0 release in reading macro definition so I applied hot-fix 10.0.2 for this issue Form engine - Script tags not working in custom form layouts10.0.2 for more detail check

https://devnet.kentico.com/download/hotfixes

After applying this hotfix version your existing syntax for localization work's fine. <h2><%= CMS.Helpers.ResHelper.GetString("Title1") %></h2>

Solution2

Check with this instead of using # use = as in error message it specify you can used it like variable. <%= Localize("Text containing localization expressions: {$stringKey$}") %>

My recommendation apply latest hotfix to avoid such kind defect's for other features and functionality.

Feel free to ask ! I m happy to assist you :)

Thanks

Prashant

3 votesVote for this answer Unmark Correct answer

Recent Answers


Chetan Sharma answered on May 17, 2017 12:00

As per this documentation

It says the way to access this value is like this and it went on to explain

{$key$} - Displays the value of the resource string with the specified key. Strings can be viewed and edited in the Localization application or in the .resx files under the CMSResources folder.

Usage - {$myform.firstname$}

Try this.

0 votesVote for this answer Mark as a Correct answer

bert limerkens answered on May 17, 2017 12:04

Yes that might work in a text/xml layout but I am using a ascx layout. If I do this it just shows {$Title$} as output.

So that is not working.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on May 17, 2017 12:18

Yes right. I checked it too. The only reason is if you add keyword new in front of this in .NET environment it will call the constructor to do the object initialization.

I don't think that should be the case here. Can you try adding new in front and see how it responds to it?

0 votesVote for this answer Mark as a Correct answer

bert limerkens answered on May 17, 2017 13:16

Hi Prashant,

I upgraded to the latest hotfix but I still get the same error. Anything else you did to fix this problem?

Thanks for your response!

0 votesVote for this answer Mark as a Correct answer

bert limerkens answered on May 17, 2017 13:26

Ok I got it working now by adding the asp:PlaceHolder tags

1 votesVote for this answer Mark as a Correct answer

Prashant Verma answered on May 17, 2017 13:31

Great !Bert

Any other help need let me know cheers!

1 votesVote for this answer Mark as a Correct answer

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