Add Search Results to UserControl
Hi,
I want to create my own usercontrol that includes various items, including your search results. I need to know what assembly your Search Results lives in and how to register and then reference it so I can add it via code.
Thanks
Ben
Hello Ben Alexandra,
The search results widget is part of the Telerik.Sitefinity assembly and can be referenced from the Telerik.Sitefinity.Services.Search.Web.UI.Public namespace. Please find below the default template we're using for the control as well:
<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
<
sfSearch:SearchBox
ID
=
"topSearchBox"
runat
=
"server"
/>
<
sitefinity:SitefinityLabel
id
=
"resultsStats"
runat
=
"server"
WrapperTagName
=
"p"
CssClass
=
"sfsearchResultStatistics"
Text="<%$Resources:SearchResources, SearchResultsStatusMessage %>" />
<
asp:Repeater
ID
=
"resultsList"
runat
=
"server"
>
<
HeaderTemplate
>
<
dl
class
=
"sfsearchResultsWrp sfsearchReultTitleSnippetUrl"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
dt
class
=
"sfsearchResultTitle"
><
a
runat
=
"server"
href='<%# Eval("Link")%>'><%# Eval("Title") %></
a
></
dt
>
<
dd
class
=
"sfsearchResultSnippet"
><%# Eval("Summary")%></
dd
>
<
dd
class
=
"sfsearchResultUrl"
><
a
runat
=
"server"
href='<%# Eval("Link")%>'><%# Eval("Link")%></
a
></
dd
>
<
dd
class
=
"sfsearchResultHighLighter"
><%# Eval("HighLighterResult")%></
dd
>
</
ItemTemplate
>
<
FooterTemplate
>
</
dl
>
</
FooterTemplate
>
</
asp:Repeater
>
<
sitefinity:Pager
ID
=
"pager"
runat
=
"server"
/>
<
sfSearch:SearchBox
ID
=
"bottomSearchBox"
runat
=
"server"
/>
Great. Thanks! I'll give it a try!
I'm afraid that didn't work. The search box shows up but in the place where it's supposed to show the results, I just get "0 search results for 1"
I dropped your search results user control on from the toolbox right above it and it returns results but something isn't firing with the code you sent.. There were some problems with the spaces in your code not coming through, but I put spaces everywhere I could think they were needed. I was getting a parser error before but now I'm not, so I think I got them all.
Let me know if you have any other ideas
Thanks!
Ben
Hi Ben Alexandra,
I have just tested this functionality, by registering a custom SearchResults widget in my project, and configuring the Search widget to display the results on the page where the custom widget is dropped (which happens to be the same page in my current example). The widget displays properly the returned results, please find attached a sample video I've recorded while testing this functionality.
Best wishes,
Boyan Barnev
the Telerik team
Hi,
Thanks for the video. That seems to work better, but doesn't allow me to customize the design like your first version. Also, so we're clear, this is totally different code (in your video) than what you pasted above, right?
Here is your NEW code (from the video) and it does seem to work:
<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
<
sfSearch:SearchResults
runat
=
"server"
ID
=
"MyResults"
></
sfSearch:SearchResults
>
<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
<
sitefinity:SitefinityLabel
id
=
"resultsStats"
runat
=
"server"
WrapperTagName
=
"p"
CssClass
=
"sfsearchResultStatistics"
Text="<% $Resources:SearchResources, SearchResultsStatusMessage %>" />
<
asp:Repeater
ID
=
"resultsList"
runat
=
"server"
>
<
HeaderTemplate
>
<
dl
class
=
"sfsearchResultsWrp sfsearchReultTitleSnippetUrl"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
dtclass
=
"sfsearchResultTitle"
><
a
runat
=
"server"
href='<%# Eval("Link")%>'><%# Eval("Title") %></
a
></
dt
>
<
ddclass
=
"sfsearchResultSnippet"
><%# Eval("Summary")%></
dd
>
<
ddclass
=
"sfsearchResultUrl"
><
a
runat
=
"server"
href='<%# Eval("Link")%>'><%# Eval("Link")%></
a
></
dd
>
<
ddclass
=
"sfsearchResultHighLighter"
><%# Eval("HighLighterResult")%></
dd
>
</
ItemTemplate
>
<
FooterTemplate
>
</
dl
>
</
FooterTemplate
>
</
asp:Repeater
>
<
sitefinity:Pager
ID
=
"pager"
runat
=
"server"
/>
Hi Ben Alexandra,
Please excuse me if I have misled you with my latest response. Let me elaborate a little bit on the two approaches we've covered so far. Starting with your initial question:
"I want to create my own usercontrol that includes various items, including your search results. I need to know what assembly your Search Results lives in and how to register and then reference it so I can add it via code."
The Search Results widget's logic is in the SearchResults class of Telerik.Sitefinity.Services.Search.Web.UI.Public namespace. You can register this namespace as a tag prefix in your user control and add the SearchResults inside your user control as I demonstrated in my latest response.
On the other hand, the SearchResults widget is using a template for the public representation of its data, this is the code I provided you with in my initial response.
If you want to modify just the visual appearance of your SearchResults control, you can simply create a custom template based on the default one we're using, and then map it to all instances of the widget throughout Sitefinity, or pass it to one widget on a page. . For more information on mapping external templates to Sitefinity 4.x widgets, please check these resources:
Customizing Sitefinity 4 Controls with the ViewMap
Mapping External Templates for Sitefinity 4 Widgets
Now if you need to change the logic of the widget, you can create a custom class, that inherits from the base SearchResults and override the out of the box logic.
If you need to modify both the logic and the visual representation of the data, you can create a custom class, that inherits from the base SearchResults, implement your own logic, and then pass the customized template to the layoutTemplatePath property of the control.
Please note that when using the template only, you're missing the code-behind logic that passes data to the Repeater inside the SearchResults template, that's why you're getting no results. On the other hand if you're just using the control inside a user control, like I demonstrated in my latest response, you can either go with the default template, or specify a customized one in the control declaration like this:
%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SearchResultsCustom.ascx.cs" Inherits="SitefinityWebApp.Controls.SearchResultsCustom" %>
<%@ Register TagPrefix="sfSearch" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" %>
This is my custom Search results widget
<
sfSearch:SearchResults
runat
=
"server"
LayoutTemplatePath
=
"~/MyCustomTemplate.ascx"
></
sfSearch:SearchResults
>
Hello