SearchDataSource.Filter event not raised

Magnus Rahl
Member since: 2008
 

Is the SearchDataSource.Filter event raised only under certain conditions? I have a page template that I use in two different "modes", either to execute a property search defined by page properties (by adding propertycriteria in codebehind) or if no such search is defined as an ordiary free text search. In free text mode the Filter event is raised just fine, but when property search is active it isn't raised. The Selected event is raised in both cases.

The code looks something like this:

protected override void OnLoad(System.EventArgs e) { base.OnLoad(e); Source.Selected += new DataSourceStatusEventHandler(Source_HandleErrors); Source.Selected += new DataSourceStatusEventHandler(Source_HandleEmptyResult); Source.Filter += new FilterEventHandler(Source_Filter); Source.Filter += new FilterEventHandler(Source_Sort); if (IsSearch) { SearchArea.Visible = true; Form.DefaultButton = SearchButton.UniqueID; } else { SearchArea.Visible = false; PropertyCriteriaCollection tagCriteria = new PropertyCriteriaCollection(); // Code to add criteria... Source.Criteria.Add(tagCriterion); } Search(); }  protected void Search_Click(object sender, EventArgs e) { Source.SearchQuery = SearchText.Text; Source.OnlyWholeWords = this.SearchOnlyWholeWords.Checked; Search(); }  protected void Search() { Result.Visible = true; NoSearchResult.Visible = false; Source.DataBind(); }

#29821 May 18, 2009 12:40
  • Magnus Rahl
    Member since: 2008
     

    I never get the hang of this code formatting, let's see if I can get the code to post in human-readable format:

    protected override void OnLoad(System.EventArgs e)
    {
    base.OnLoad(e);
    Source.Selected += new DataSourceStatusEventHandler(Source_HandleErrors);
    Source.Selected += new DataSourceStatusEventHandler(Source_HandleEmptyResult);
    Source.Filter += new FilterEventHandler(Source_Filter);
    Source.Filter += new FilterEventHandler(Source_Sort);

    if (IsSearch)
    {
    SearchArea.Visible = true;
    Form.DefaultButton = SearchButton.UniqueID;
    }
    else
    {
    SearchArea.Visible = false;
    PropertyCriteriaControl tagCriterion = new PropertyCriteriaControl();
    tagCriterion.Name = // Omitted lines to set up criteria...

    Source.Criteria.Add(tagCriterion);
    }
    Search();
    }

    protected void Search_Click(object sender, EventArgs e)
    {
    Source.SearchQuery = SearchText.Text;
    Source.OnlyWholeWords = this.SearchOnlyWholeWords.Checked;
    Search();
    }

    protected void Search()
    {
    Result.Visible = true;
    NoSearchResult.Visible = false;
    Source.DataBind();
    }

    #29822 Edited, May 18, 2009 12:41
  • Magnus Rahl
    Member since: 2008
     

    I looked at the code using Reflector and as far as I can see the Filter event is never raised if executing a property search. This is documented - in a way. My interpretation of the documentation was that if you perform a free text search, any proprety criteria are used to filter the result set (using automatically created handlers for the Filter event). However, any manually added filter should still be executed. This is not the case. Is there a good reason for this behaviour, is it a bug, or did I miss something?

    I worked around the problem for now by not using the SearchDataSource for my property search but using FindPagesWithCriteria directly to get hold of the PageDataCollection and filter it.

    #29840 May 19, 2009 7:56
  • Mari Jørgensen
    Member since: 2003
     
    This has been registered as a bug:

    #24819: SearchDataSource.Filter event isn't raised when property search is active

     

    #30164 Jun 03, 2009 14:50