In this recipe, we will create a public event from the SearchControl, so that we can subscribe to the PART_Button button event and fetch the user-entered text. To do so, follow perform the following steps:
- From Solution Explorer, create a new class named SearchEventArgs, inside the project.
- Extend the SearchEventArgs class from the EventArgs and expose a public property (SearchTerm) of type string. Here's the class implementation:
public class SearchEventArgs : EventArgs { public string SearchTerm { get; set; } }
- Now open the SearchControl.cs file. We need to create a delegate and event inside it. Let's add the following inside the class implementation:
public delegate void OnSearchClick(object sender, SearchEventArgs e); public event OnSearchClick SearchButtonClick;
- The next task is to associate the button click event with the custom event that we have just created. Pass the SearchTerm to the custom event as an argument. To do this, copy the...