Monday, September 8, 2008

Using Google Co-op's Custom Search Engine

By Jon Sagara

This article shows how easy it is to use ASP.NET and Google Co-op's Custom Search Engine to build your own search engine.

This article shows how easy it is to create your own custom search engine using ASP.NET and Google Co-op’s Custom Search Engine feature.

Creating Your Search Engine
The very first step you must take is to visit (Note that you must have a Google Account. If you don’t have one, ask around. GMail invites are a dime a dozen these days.) Once there, follow the instructions to create your custom search engine.

For this article, I used the following settings:

Sites to Search
Sites to search:
How to search these sites: Search only these sites.

Collaborate with others
Who can collaborate: Only people I invite may contribute to this search engine.

Where to Host the Custom Search Engine
You have two options on how you can display your search engine to users: Google can host it for you, or you can host the search box and results on your site. For this article, I opted for the latter.

To configure this option:

Return to the Google Co-op Custom Search Engine site’s home page (
Click on the My Search Engines link.
When the list of your custom search engines shows up, click on the link that says “Control Panel.”
Next, click on the link that says “Code”.
Select the radio button next to the option that says “Host a search box and search results on your own site…”
Also, specify the URL of the page on your site where you want the search results to appear.
Finally, after you select the location where you want to display the AdSense ads in your search results, click the Save Changes button.
Search Box code and Search Results code
On that same “Code” page in your custom search engine control panel, you will see two multi-line text boxes containing JavaScript code. The first contains a small form that contains your search box; the second is pure JavaScript that aids in the rendering of your search results.

Using the Google-generated Search Box code outside of the server-side FORM tag.
You can use the search box code generated by Google provided you place it outside of your Web form’s server-side FORM tag. I tested this locally, and it worked beautifully. However, I’m sure I’m not alone in wanting the ability to put the search box somewhere inside the server-side FORM tag and still having my custom search engine operate correctly.

Using ASP.NET server controls and HtmlControls to emulate Google’s search box inside the server-side FORM tag
I solved this problem by using ASP.NET server controls and HtmlControls to emulate the behavior of Google’s search box FORM, while still providing the server-side capabilities that we all know and love.

You’ll need to reference the search box JavaScript/HTML code from the Custom Search Engine control panel. I simply included it in my ASPX page in an HTML comment. This is what it looks like:


ASP.Net Feeds