I’ve finally deployed the DotNetNuke site I’ve been working on. After deployment is when the most obvious things pop up.
For instance, in DotNetNuke when you search for something in the site it will return a list of links to what it finds. What it won’t do is display something friendly like “No Search Results Found” if it doesn’t find anything. Dumb and not very user friendly.
I did find what I thought would be the solution at ecktwo, but it didn’t work in Firefox due to the
document.getElementById("search").innerHTML
which doesn’t work in Firefox within a table, which is what the Search Results are generated using the ASP.NET grid view. So, I thought I’d take a stab at building something that worked for both IE and Firefox.
Make a copy of your admin\Search\SearchResults.ascx file and then open the file in notepad. Apply the following code that I’ve highlighted in red:
<%@ Control Language=”vb” AutoEventWireup=”false” Explicit=”True” Inherits=”DotNetNuke.Modules.SearchResults.SearchResults” CodeFile=”SearchResults.ascx.vb” %>
<asp:Datagrid id=”dgResults” runat=”server” AutoGenerateColumns=”False” AllowPaging=”True” BorderStyle=”None”
PagerStyle-CssClass=”NormalBold” ShowHeader=”False” CellPadding=”4″ GridLines=”None”>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label id=lblNo runat=”server” Text='<%# DataBinder.Eval(Container, “ItemIndex”) + 1 %>’ CssClass=”SubHead”>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink id=”lnkTitle” runat=”server” Name=”result” CssClass=”SubHead” NavigateUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem,”TabId”),
DataBinder.Eval(Container.DataItem,”Guid”)) %>’ Text='<%# DataBinder.Eval(Container.DataItem, “Title”) %>’>
</asp:HyperLink> -
<asp:Label id=”lblRelevance” runat=”server” CssClass=”Normal” Text='<%# FormatRelevance(DataBinder.Eval(Container.DataItem, “Relevance”)) %>’ >
</asp:Label><BR>
<asp:Label id=”lblSummary” runat=”server” CssClass=”Normal” Text='<%# DataBinder.Eval(Container.DataItem, “Description”) + “<br>” %>’ Visible=”<%# ShowDescription() %>”>
</asp:Label>
<asp:HyperLink id=”lnkLink” runat=”server” CssClass=”CommandButton” NavigateUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem,”TabId”),
DataBinder.Eval(Container.DataItem,”Guid”)) %>’ Text='<%# FormatURL(DataBinder.Eval(Container.DataItem,”TabId”),
DataBinder.Eval(Container.DataItem,”Guid”)) %>’>
</asp:HyperLink> -
<asp:Label id=”lblPubDate” runat=”server” CssClass=”Normal” Text='<%# FormatDate(DataBinder.Eval(Container.DataItem, “PubDate”)) %>’>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle CssClass=”NormalBold” Mode=”NumericPages”></PagerStyle>
</asp:Datagrid>
<div id=”NoResults”>
<h3 class=”red” style=”text-align:center”>No Search Results Found</h3>
</div>
<script language =”Javascript”>
var search;
search = document.getElementsByName(“result”);
if (search.length == 0) {
document.getElementById(“NoResults”).style.display=’block’;
}
else {
document.getElementById(“NoResults”).style.display=’none’;
}
</script>
Be sure to add the Name=”result” snippet to the asp:Hyperlink in the code above. It’s easy to miss.
Save that and you should now have a spiffy new message displayed when no results are found. Use whatever CSS you want to style the message.