Google "Adsense for Search" is a great way to easily allow visitors to search for content on your site. Not only is this service free, but Google will pay you if visitors click ads displayed on the search results page. Begin by setting up an account at adsense.Google.com, then setup a custom “Adsense for Search” and save the generated code.

Example site search code:

<!-- SiteSearch Google -->
<form method="get" action="http://www.google.com/custom" target="_top">
<table border="0" bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle"></img></a>
</td>
<td nowrap="nowrap">
<input type="hidden" name="domains" value="mydomain.com"></input>
<label for="sbi" style="display: none">Enter your search terms</label>
<input type="text" name="q" size="31" maxlength="255" value="" id="sbi"></input>
<label for="sbb" style="display: none">Submit search form</label>
<input type="submit" name="sa" value="Search" id="sbb"></input>
</td></tr><tr><td>&nbsp;</td><td nowrap="nowrap"><table>
<tr><td>
<input type="radio" name="sitesearch" value="" checked id="ss0"></input>
<label for="ss0" title="Search the Web"><font size="-1" color="#000000">Web</font></label></td>
<td>
<input type="radio" name="sitesearch" value="mydomain.com" id="ss1"></input>
<label for="ss1" title="Search mydomain.com"><font size="-1" color="#000000">mydomain.com</font></label></td>
</tr>
</table>
<input type="hidden" name="client" value="pub-123"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="channel" value="123"></input>
<input type="hidden" name="ie" value="ISO-8859-1"></input>
<input type="hidden" name="oe" value="ISO-8859-1"></input>
<input type="hidden" name="cof" value="G..."></input>
<input type="hidden" name="hl" value="en"></input>
</td></tr></table>
</form>
<!-- SiteSearch Google -->

This generated code uses a FORM to perform a site search, but this will not work by simply copy/pasting into a ASP.NET site. There are a few ways to get this working, but I prefer to remove the form and build a query string as shown below.

Example modified site search code:

<!-- SiteSearch Google -->
<script type="text/javascript">
function GoogleSearch(q) {
window.location = "http://www.google.com/custom" +
"?q=" + q +
"&domains=mydomain.com" +
"&sitesearch=mydomain.com" +
"&forid=1" +
"&channel=123" +
"&client=pub-123" +
"&ie=ISO-8859-1" +
"&oe=ISO-8859-1" +
"&hl=en";}
</script>
<a href="http://www.google.com/"><img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle" /></a>
<label for="sbi" style="display: none">Enter your search terms</label>
<input type="text" name="q" size="30" maxlength="255" value="" id="sbi" />
<label for="sbb" style="display: none">Submit search form</label>
<asp:Button ID="sbb" OnClientClick="GoogleSearch(q.value);return false;" Text="Search Site" runat=server />
<!-- SiteSearch Google -->

Notice the FORM is now gone and the appropriate values are simply passed in the Query String. The modified code is shorter because I also removed the HTML TABLES and other properties that I did not need. Other properties can be added to further customize the search results page, simply get the example code from Google Adsense and modify as demonstrated above.

To also allow visitors to perform a search by hitting the Enter key after typing in a keyword be sure to wrap the code in a PANEL, setting the default button property to “sbb”.
Ex:

<asp:Panel ID="Panel_goog" runat="server" DefaultButton="sbb">

*Note: In order for Google site search to work your site will need to be indexed by Google. Check to make sure you show up on Google by searching for "site:yourdomain" on Google.com. Submit a site map to Google if not already indexed.