Prev | Current Page 775 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"


Handling the Search
The top of Search.HandleSearch has code that checks an internal Boolean variable named
searchHandled to make sure that if both events fire on the same postback, we don??™t get duplicate
searches occurring on the same query value unnecessarily, as shown here:
CHAPTER 12 ?–  BUILDING A COMPLEX CONTROL 597
// check to see if search was handled on this postback
// (this prevents TextChanged and ButtonClicked from
// requesting the same query twice on the Live Search web service)
if (searchHandled == true)
return;
// check for redirect of query processing to Live Search web site
if (RedirectToLiveSearch == true)
{
this.Page.Response.Redirect(
LiveSearchWebSearchUrl + "?q=" +
HttpContext.Current.Server.UrlEncode(Query), true);
}
In HandleSearch, there is code that looks at the RedirectToLiveSearch property to decide
whether to send the query back to the Live Search web site with Response.Redirect. The Query
property is put on the URL string using the q variable on the HTTP GET string to accomplish
this.
If we choose not to redirect the query to Live Search, we use the SearchUtility class to
receive a SearchResponse from the web service proxy code it wraps. The ResultControl property
of the Search control is used to do a dynamic lookup of the correct Result control via the Page
FindControl method.


Pages:
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787