Smart search box adding comma to smart search dialog box

Kayla Johnson asked on December 4, 2017 15:34

On our client site we have a Smart search box web part in the header of every page. When you search through this, it takes you to the Search page. On the Search page is a Smart search dialog web part. Whenever a user comes to the Search page via this Smart Search Box in the header, it removes the term from that box, which is less of an issue, but it is adding a comma to the beginning of the search term in the Smart Search Box on the actual Search page. It's still searching the right way and pulling the right results. Also if you change the search term in the Smart Search Dialog in the sidebar it does not add a comma when you search.

https://pasteboard.co/GWF0XFM.png

See screenshot where the top box has the search term removed even though I searched through that box initially. And the term in the sidebar has a comma before the term.

Correct Answer

Kayla Johnson answered on December 5, 2017 22:50

Turns out the search box can't be inside a div with an id of header or in a <header> tag. That was my solution. To rename my div id="header" to div id="pageheader". In what world that makes sense, idk...

0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on December 4, 2017 16:00 (last edited on December 4, 2017 16:05)

That probably the result that "searchtext" (or whatever your search parameter name is) has been added twice for example

www.yoursite.com/Search.aspx?searchtext=test&searchmode=anyword&searchtext= or you pass it by post and by querystring at the same time and combine them.

0 votesVote for this answer Mark as a Correct answer

Kayla Johnson answered on December 4, 2017 16:05

When I search in the header's search box the url is something like this: Search.aspx?searchtext=%2ctravel&searchmode=anyword

0 votesVote for this answer Mark as a Correct answer

Kayla Johnson answered on December 4, 2017 16:10

Okay also if I search without putting a term it's pulling back results related to icons. I think this is because I'm using an image for the search button. Why is this a thing? If I'm using built-in web parts to kentico why do they have such buggy implementation? and how do I fix?

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on December 4, 2017 16:14 (last edited on December 4, 2017 16:20)

if you URL decode your searchtext parameter value, the first symbol %2c is actually , . So the problem is somehwere in your code where your form your searchtext parameter.

P.S. It could be the that the smart search box has been added twice to the template.

0 votesVote for this answer Mark as a Correct answer

Kayla Johnson answered on December 4, 2017 16:22 (last edited on December 4, 2017 16:22)

I get that the %2c is a comma but why is it even happening? I am using an out of the box web part from kentico. It shouldn't be an issue with my code as I have no code. The only thing I'm changing in the web part settings it to use an image button instead. And now even taking that off and just using a standard submit button, it is still doing that.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on December 4, 2017 16:26

Can you give us the url of your site so we can take a look?

0 votesVote for this answer Mark as a Correct answer

Kayla Johnson answered on December 4, 2017 16:56

We can't do that. It's an intranet for a client. It's pretty locked down.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on December 4, 2017 17:21

I suggest you examine the page source code (you do in the browser view page source) search for something like searchTextbox. Do it on the page where you perform the search first.

0 votesVote for this answer Mark as a Correct answer

Kayla Johnson answered on December 4, 2017 17:31

That doesn't exist in the source. This is the code for the search form in the header

<div id="p_lt_ctl01_SmartSearchBox1_pnlSearch" class="searchBox mobile-hidden" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'p_lt_ctl01_SmartSearchBox1_btnSearch')">

    <label for="p_lt_ctl01_SmartSearchBox1_txtWord" id="p_lt_ctl01_SmartSearchBox1_lblSearch" style="display:none;">Search for:</label>
<input name="p$lt$ctl01$SmartSearchBox1$txtWord" type="text" maxlength="1000" id="p_lt_ctl01_SmartSearchBox1_txtWord" class="form-control">
    <input type="submit" name="p$lt$ctl01$SmartSearchBox1$btnSearch" value="Search" id="p_lt_ctl01_SmartSearchBox1_btnSearch" class="search-icon btn btn-default">

    <div id="p_lt_ctl01_SmartSearchBox1_pnlPredictiveResultsHolder" class="predictiveSearchHolder">

</div>

0 votesVote for this answer Mark as a Correct answer

Kayla Johnson answered on December 5, 2017 15:36

The comma is going before the searched term, implying that whatever else is on the page interfering is before the input field in the DOM. But I've removed all the other web parts before it. And it still has this behavior. What is up with this? I'm literally using an out of the box web part. I have no access to change any of the code. I've been working in the base setup with the dummy Kentico Intranet data installed from the client. No customizations. Why would this get messed up? I'm running into a wall here.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on December 5, 2017 16:13 (last edited on December 5, 2017 16:14)

It is really hard to do remote debugging :). Although you do have access to some code if you can physically access files on disk. The default web part code is located in CMS\CMSWebParts\SmartSearch\SearchBox.ascx.cs. There is a method that does submission around line 820::

private void Search()
{
    string url = SearchResultsPageUrl;

    if (url.StartsWithCSafe("~"))
    {
        url = ResolveUrl(url.Trim());
    }

    url = URLHelper.UpdateParameterInUrl(url, "searchtext", HttpUtility.UrlEncode(txtWord.Text));
    url = URLHelper.UpdateParameterInUrl(url, "searchmode", SearchMode.ToStringRepresentation());

    // Log "internal search" activity
    Activity internalSearch = new ActivityInternalSearch(txtWord.Text, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables);
    internalSearch.Log();

    // Try remove paging parameter
    url = URLHelper.RemoveParameterFromUrl(url, "page");

    URLHelper.Redirect(url.Trim());
}

You can put a break point and debug (if have access of course). For starters if you don't have access to the code do this:

  • create a new blank template or use existing one.
  • put smart search box web part there with the same setting like you have on the home page
  • see if it is working correctly,i.e. the result url doesntcontain any weird shit i.e the result url is correct /Search.aspx?searchtext=test&searchmode=anyword
  • if it is working correctly on the blank template it means the problem is with your template.
  • There something there that causes the issue you may try to disable all web parts and start submitting search again and enable them one by one till you pin point the one that causes a conflict.

P.S. Save code from view source and upload it somewhere so we can take a look.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.