Question

I am trying to customize the text displayed in the search box of my SharePoint site. The default is "Search this site...".

I found a number of articles which explain how to do it (by overriding the delegate control with a lower sequence number) and it works fine.

My XML looks like this :

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Control
        Id="SmallSearchInputBox"
        Sequence="10"
        ControlClass="Microsoft.SharePoint.Portal.WebControls.SearchBoxEx" ControlAssembly="Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
        <Property Name="GoImageUrl">/_layouts/images/gosearch15.png</Property>
        <Property Name="GoImageUrlRTL">/_layouts/images/gosearchrtl15.png</Property>
        <Property Name="GoImageActiveUrl">/_layouts/images/gosearchhover15.png</Property>
        <Property Name="GoImageActiveUrlRTL">/_layouts/images/gosearchrtlhover15.png</Property>
        <Property Name="DropDownMode">ShowDD</Property>
        <Property Name="SearchResultPageURL">/_layouts/osssearchresults.aspx</Property>
        <Property Name="ScopeDisplayGroupName"></Property>
        <Property Name="FrameType">None</Property>
        <Property Name="QueryPromptString">DO A SEARCH!</Property>
    </Control>
</Elements>

This works fine, the search box displays "DO A SEARCH!" as expected. However, I want this string localized. When I do

<Property Name="QueryPromptString">$Resources:MyResourceFile,CustomText;</Property>

The search box displays $Resources:MyResourceFile,CustomeText; litterally instead of evaluating it.

How do I put localized strings there?

Thanks!

Was it helpful?

Solution

The line <Property Name="QueryPromptString">$Resources:MyResourceFile,ResourceKey</Property> wokrs fine for me. I think that you should check your resources file. This file should contain ResourceKey which you tries to use in this property.

If you use correct resource file and key, the search control displays text depends on the site language. If you would like to change this text dynamically as you see in the picture below, you should do some more complex steps.

enter image description here

steps:

  1. Create you custom class and inherit it from SearchBoxEx
  2. Create new QueryPromptString property
  3. Define safe control
  4. Create delegate control

code for steps:

public class SearchBox : SearchBoxEx
{
    [Browsable(false)]
    public new string QueryPromptString
    {
        get
        {
            return base.QueryPromptString;
        }
        set
        {
            string fullKey = string.Format("$Resources:{0}", value);
            base.QueryPromptString = SPUtility.GetLocalizedString(fullKey, null, (uint)Thread.CurrentThread.CurrentUICulture.LCID);
        }
    }
}

<Control Id="SmallSearchInputBox"
           Sequence="10"
           ControlClass="LocalizedSearch.SearchBox"
           ControlAssembly="LocalizedSearch, Version=1.0.0.0, Culture=neutral, PublicKeyToken=71df3f77c17b7c69">
        <Property Name="GoImageUrl">/_layouts/images/gosearch15.png</Property>
        <Property Name="GoImageUrlRTL">/_layouts/images/gosearchrtl15.png</Property>
        <Property Name="GoImageActiveUrl">/_layouts/images/gosearchhover15.png</Property>
        <Property Name="GoImageActiveUrlRTL">/_layouts/images/gosearchrtlhover15.png</Property>
        <Property Name="DropDownMode">ShowDD</Property>
        <Property Name="SearchResultPageURL">/_layouts/osssearchresults.aspx</Property>
        <Property Name="ScopeDisplayGroupName"></Property>
        <Property Name="FrameType">None</Property>
        <Property Name="QueryPromptString">filename,key</Property>
  </Control>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top