Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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>
share|improve this answer
    
Thanks Alexander, you are right, the line was correct. However, I was pointing to an application resource file where I needed to point to a provisioning resource file. Once I moved the ResourceKey from one file to the other, it worked. –  Hugo Migneron May 24 '12 at 15:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.