none
Extended Search Box button override method

    Question

  • HI all,

     I extended the search box using the link "http://blogs.msdn.com/b/stevennicolaou/archive/2010/06/24/extend-the-search-box-web-part-in-sharepoint-2010.aspx "  and now i need to override that search box button click event. If i put a breakpoint in   "override  CreateChildControls()" method and click on the extended search box button it is not going into that method. So Please tell me how to take the control of extended search box button click event.. Please help me out...


    Sharath Kumar R

    Friday, July 20, 2012 10:12 AM

Answers

  • Hi,

    You should not change search.js, merely emit javascript code in your page which captures the call to GoSearch. In my case I already had a customized searchbox webpart so I could register the script from the webpart.

    If it's a site wide change you can add the Override function and the registration line below to your master page.

    ExecuteOrDelayUntilScriptLoaded(Override,'search.js');

    Basically you need to add it to your page at some point, master page, page layout, content web part.. as long as it's executed on the page in order to capture and override calls to GoSearch.

    As for registering the script in PreRender take a look at http://www.dotnetcurry.com/ShowArticle.aspx?ID=200 (or any other result on Google)

    Thanks,
    Mikael Svenson


    Search Enthusiast - SharePoint MVP/MCT/MCPD
    http://techmikael.blogspot.com/
    Author of Working with FAST Search Server 2010 for SharePoint

    • Marked as answer by kumar sharath Tuesday, September 18, 2012 10:34 AM
    Thursday, July 26, 2012 6:53 PM

All replies

  • Hi,

    Depending on what you want to achieve, you might not have to override the search box button, but override the javascript it calls. When clicking "search" a javascript function called GoSearch() is called. I haven't looked into it, but it might be the same one being called on the advanced search page. Check out my post "Adding prefix logic to the ribbon search box" for how to override the javascript being called when the button is clicked.

    Thanks,
    Mikael Svenson


    Search Enthusiast - SharePoint MVP/MCT/MCPD
    http://techmikael.blogspot.com/
    Author of Working with FAST Search Server 2010 for SharePoint

    Saturday, July 21, 2012 5:51 PM
  • Hi,

          Thanks for your post. I had gone through your post "Adding prefix logic to the ribbon search box" http://techmikael.blogspot.se/2012/06/adding-prefix-logic-to-ribbon-search.html. I need to do the same what you have given in that post. I tried to override the gosearch function in search.js  javascript. Now on page refresh, it is going to onprerender method. On that method, i am calling the javascript but it is not happening. Can you explain in detail how you have done it. Also can u say how to use this.Page.ClientScript.RegisterStartupScript() ..


    Sharath Kumar R

    Thursday, July 26, 2012 2:11 PM
  • Hi,

    You should not change search.js, merely emit javascript code in your page which captures the call to GoSearch. In my case I already had a customized searchbox webpart so I could register the script from the webpart.

    If it's a site wide change you can add the Override function and the registration line below to your master page.

    ExecuteOrDelayUntilScriptLoaded(Override,'search.js');

    Basically you need to add it to your page at some point, master page, page layout, content web part.. as long as it's executed on the page in order to capture and override calls to GoSearch.

    As for registering the script in PreRender take a look at http://www.dotnetcurry.com/ShowArticle.aspx?ID=200 (or any other result on Google)

    Thanks,
    Mikael Svenson


    Search Enthusiast - SharePoint MVP/MCT/MCPD
    http://techmikael.blogspot.com/
    Author of Working with FAST Search Server 2010 for SharePoint

    • Marked as answer by kumar sharath Tuesday, September 18, 2012 10:34 AM
    Thursday, July 26, 2012 6:53 PM
  • Hi Sharath,

    As you have Inherited your class from SearchBoxEx, it has a field of type Textbox m_searchKeyWordTextBox, In createChildControls method, You can simply use method Attributes.Add("onClick","MyGoSearch()"); to this object and implement your custom logic in MyGoSearch() javascript function.

    Hope, It work for you.

    Umashankar.

    
    
    
    
    
    
    
    
    

    umashankar

    Sunday, July 29, 2012 7:29 AM
  • Hi Svenson,

             When I search a keyword in search centre site, I am getting some suggestions. Now On the click of that suggestion, results are getting dispalyed. These are the default search box behaviour. But that suggestion should come to the searchbox and after clicking on that searchbox, results should come.

    So I need to get the event of that query suggestion hit. Please let me know how to override that function or event. Thanks!


    Sharath Kumar R


    Wednesday, December 05, 2012 10:00 AM
  • Hi Sharath,

    When we look at the page source of Search Box web part for "AjaxControlToolkit.AutoCompleteBehavior", we can identify the function which is called when any of the OOB suggestion is selected. For this, search "enterKeyDownScript" in page source, we will find

    "enterKeyDownScript":"*********_Submit()". Click of suggestion can be suppressed by override this function to do nothing  in document.ready function as

    window.*********_Submit = function () { };

    As value before "*********" _Submit is different for each search box web part, we need to override all instances.

    Hope, you find it usefull.

    There may be even better approach to accomplish this. I appreciate any new suggestion.

    Thanks and Regards.

    Umashankar


    umashankar

    Thursday, December 06, 2012 7:09 AM