Wednesday, August 25, 2010

How to add google custom search to your asp.net page with Master Page

Master page
<%@ Master Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head2" runat="server">
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
    <script runat="server">
        public string RootUrl
        {
            get
            {
                Uri requestUri = Context.Request.Url;
                HttpRequest request = Context.Request;
                string rootUrl = string.Format("{0}{1}{2}{3}{4}",
                    requestUri.Scheme,
                    Uri.SchemeDelimiter,
                    requestUri.Host,
                    requestUri.IsDefaultPort ?
                        string.Empty : string.Format(":{0}", requestUri.Port),
                    request.ApplicationPath);
                return rootUrl.EndsWith("/") ? rootUrl :
                        string.Format("{0}/", rootUrl);
            }
        }
    </script>
</head>
<body>
    <form id="Form2" runat="server">
        <div id="search">
            <iframe 
                src="<%=this.RootUrl %>Search.html" 
                class="SearchContainer" 
                frameborder="0" 
                scrolling="no">
                <b>Your browser does not support frames</b>
            </iframe>
        </div>
        <asp:ContentPlaceHolder ID="MainContent" runat="server" />  
    </form>
</body>
</html>
Search html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <style type="text/css">
    </style>
</head>
<body>
    <form target="_blank" id="searchForm" method="get" action="http://www.google.com/custom">
        <span id="searchText"><em>Search</em></span>
        <input id="searchInput" type="text" name="q" title="Search www.charith.gunasekara.web-sphere.co.uk" />
        <input id="searchButton" type="submit" value="Search" title="Search" />
  <input type="hidden" name="domains" value="http://www.charith.gunasekara.web-sphere.co.uk" />
  <input type="hidden" name="sitesearch" value="http://www.charith.gunasekara.web-sphere.co.uk" />        
    </form>
</body>
</html>
 

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...