自定义SmallSearchInputbox默认文本
-
09-12-2019 - |
题
我正在尝试自定义SharePoint站点的搜索框中显示的文本。默认值是“搜索本网站......”。
我发现了一些解释了如何执行此操作的文章(通过将委托控制覆盖使用较低的序列号),它可以正常工作。
我的XML看起来如此:
<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>
.
工作正常,搜索框显示“搜索!”正如预期的那样。但是,我希望这个字符串本地化。当我做
<Property Name="QueryPromptString">$Resources:MyResourceFile,CustomText;</Property>
.
搜索框显示$资源:myResourcefile,customeText;物质而不是评估它。
如何将本地化字符串放在那里?
谢谢!
解决方案
行生成的Wokrs对我很好。 我认为你应该检查你的资源文件。此文件应包含您尝试在此属性中使用的ResourceKey。
如果使用正确的资源文件和键,则搜索控件显示文本取决于站点语言。如果您想在下面的图片中动态地动态更改此文本,则应执行一些更复杂的步骤。
步骤:
- 创建自定义类并从searchboxex 继承它
- 创建新的querypromptstring属性
- 定义安全控制
- 创建委托控制
步骤代码:
.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>