Skip to content

Instantly share code, notes, and snippets.

@codecowboy
Created December 9, 2011 12:58
Show Gist options
  • Save codecowboy/1451435 to your computer and use it in GitHub Desktop.
Save codecowboy/1451435 to your computer and use it in GitHub Desktop.
search page
<%@ Page Title="" Language="C#" MasterPageFile="~/Content.master" AutoEventWireup="true" CodeFile="search.aspx.cs" Inherits="footer_search" %>
<asp:Content ID="Content8" ContentPlaceHolderID="searchScript" Runat="Server">
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
google.load('search', '1');
function OnLoad() {
// Create a search control
var searchControl = new google.search.SearchControl();
// Add in a WebSearch
var webSearch = new google.search.WebSearch();
//Add in a Searcher Option
var options = new google.search.SearcherOptions();
//Sets it to display 8 results per page
options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
searchControl.setResultSetSize(8);
//search results should not open in a new page (the default), they should target _self
searchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF)
// Restrict our search to pages from our CSE
webSearch.setSiteRestriction('removed');
// Add the searcher to the SearchControl
searchControl.addSearcher(webSearch, options);
// tell the searcher to draw itself and tell it where to attach
searchControl.draw(document.getElementById("cse"));
// execute an inital search
searchControl.execute(document.getElementById("ctl00_bodyContent_hiddenText").innerHTML);
}
google.setOnLoadCallback(OnLoad);
});
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="bodyContent" Runat="Server">
<h1>Search results</h1>
<div id="searchResultsWrapper">
<div id="ctl00_bodyContent_hiddenText" runat="server"><%= (Session["SearchValue"] != null ? Session["SearchValue"].ToString() : "")%></div>
<%Session["SearchValue"] = null; %>
<div id="cse">Loading data from Google</div>
</div>
<p><img src="/images/spacer.png" style="width:610px; height:300px" alt=""/></p>
</asp:Content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment