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:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...