Approved
Last Updated: 14 Jun 2019 08:50 by ADMIN
Thomas
Created on: 14 Jun 2019 08:40
Category: SearchBox
Type: Bug Report
0
Show Tooltip of RadSearchButton
The Tooltip property of the SearchBoxButton in the Buttons collection of the RadSearchBox is not rendered on the button element client-side.
1 comment
ADMIN
Peter Milchev
Posted on: 14 Jun 2019 08:46
Hello Thomas,

A temporary workaround can be getting all the tooltips and saving them in a Dictionary where the key is the CommandName, and on the client, setting the title attribute of the buttons so that the tooltips are available.

<script>
    function OnClientLoad(sender, args) {
        var hiddenfield = $telerik.findElement(sender.get_element().parentElement, "RadSearchBoxDocumentTooltips");
        if (hiddenfield.value) {
            var tooltips = JSON.parse(hiddenfield.value)
            sender.get_buttons().forEach(function (btn) {
                if (tooltips[btn.get_commandName()]) {
                    btn.get_element().title = tooltips[btn.get_commandName()];
                }
            })
        }
    }
</script>


<asp:Panel runat="server">
    <telerik:RadSearchBox RenderMode="Lightweight" runat="server" ID="RadSearchBoxDocument"
        EmptyMessage="Search Document" OnLoad="RadSearchBoxDocument_Load" OnClientLoad="OnClientLoad">
        <Buttons>
            <telerik:SearchBoxButton runat="server" ToolTip="Custom Button Tooltip" CommandName="Edit" ImageUrl="https://via.placeholder.com/16" />
        </Buttons>
    </telerik:RadSearchBox>
    <asp:HiddenField ID="RadSearchBoxDocumentTooltips" runat="server" />
</asp:Panel>

protected void RadSearchBoxDocument_Load(object sender, EventArgs e)
{
    var sb = sender as RadSearchBox;
    var hiddenField = sb.Parent.FindControl(sb.ID + "Tooltips") as HiddenField;
 
    var tooltips = new Dictionary<string, string>();
 
    foreach (SearchBoxButton btn in sb.Buttons)
    {
        if (!string.IsNullOrWhiteSpace(btn.ToolTip))
        {
            tooltips.Add(btn.CommandName, btn.ToolTip);
        }
    }
    if (tooltips.Count > 0)
    {
        hiddenField.Value = new JavaScriptSerializer().Serialize(tooltips);
    }
}


Regards,
Peter Milchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.