1
votes

I've duplicated the search box webpart so i can make changes. I'm trying to add a localization string to the placeholder attribute.

This isn't working:

<cms:CMSTextBox ID="txtWord" runat="server" EnableViewState="false" MaxLength="1000"
  ProcessMacroSecurity="false" placeholder="<%= CMS.Helpers.ResHelper.GetString("kff.Search--PlaceHolderCopy")%>" />

nor does this:

<cms:CMSTextBox ID="txtWord" runat="server" EnableViewState="false" MaxLength="1000"
  ProcessMacroSecurity="false" placeholder='<%= CMS.Helpers.ResHelper.GetString("kff.Search--PlaceHolderCopy")%>' />

I have a JS Snippet that does work, but i'm hoping to avoid copy in JS files.

  var $searchField = $('.searchTextbox');

  if ($('body').hasClass('ENCA')) {
    // search field placeholder copy      
    $searchField.attr('placeholder', 'Search For Stuff');
  }
  else {
    $searchField.attr('placeholder', 'Recherche');
  }

Can I add the localization string to the server tag, or should it be done in the code behind. I'm not sure the best location in the code behind for this either, I can't see a Page_Load block.

2

2 Answers

1
votes

You could add the following line in the SetupControl method in the codebehind:

txtWord.Attributes.Add("placeholder", ResHelper.GetString("kff.Search--PlaceHolderCopy"));

You cannot really use the <%= syntax to set properties of server-side controls.

Also, please note that the CMSTextBox control has a WatermarkText property, which might be what you are looking for. It uses the TextBoxWatermarkExtender control from the AjaxControlToolkit library.

0
votes

There is no need to duplicate the webpart and have duplicate code just for something this simple. Just create a different webpart layout for that webpart and add the following code above the Panel:

<script runat="server">
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        txtWord.Attributes.Add("placeholder", ResHelper.GetString("yourstring"));
    }
</script>