locked
Placing Google Custom Search Engine in ASP.Net project. RRS feed

  • Question

  • User-1253409855 posted

    I am using the Iframe version of the Google Custom Search Engine (CSE) for my asp.net website.

    I followed this tutorial

    http://www.doshdosh.com/how-to-set-up-google-custom-search-and-make-money/

    The plan is to have the textbox and button on the master page so when they search it will take them to Results.aspx. When I click however nothing happens. 

    I think it may be because I have a <form> tag inside of the asp.net main <form>  tag. Is there a way to solve this problem and still use the Google Search Engine on my website?


    Heres my code:

        <div id="searchContainer" style="float:right">
                    <form action="http://localhost:51734/pages/Results.aspx" id="cse-search-box">
                <div>
                    <input type="hidden" name="cx" value="007526145264306847822:l6lp1k1hgi4" />
                    <input type="hidden" name="cof" value="FORID:9" />
                    <input type="hidden" name="ie" value="UTF-8" />
                    <input type="text" name="q" size="25" />
                    <input type="submit" name="sa" value="Search" />
                </div>
                </form>
                        <div>
                            <img src="images/googleBG.PNG" />
                        </div>
                    </div>
    


    ^^That is the textbox and search button. And on Results.aspx I have this code.

    <asp:Content ID="Content2" ContentPlaceHolderID="contentMainPlaceHolder" runat="server">
        <div id="cse-search-results"></div>
    <script type="text/javascript">
      var googleSearchIframeName = "cse-search-results";
      var googleSearchFormName = "cse-search-box";
      var googleSearchFrameWidth = 600;
      var googleSearchDomain = "www.google.com";
      var googleSearchPath = "/cse";
    </script>
    <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
    </asp:Content>
    


    Anyone here have experience with the Google CSE?



    Wednesday, May 19, 2010 6:30 PM

Answers

  • User-1712518563 posted

     Here is my complete code:

    <div id="search" style="background-color: #000000; text-align: center; ; right: 0px;" >
    						<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
    						<script language="javascript" type="text/javascript">
                    function GoogleSiteSerach() {
                        document.location.href = 'http://www.benzonly.com/search.aspx?cx=partner-pub-9662148617393694%3Aw7wb6i-arla&cof=FORID%3A9&ie=ISO-8859-1&q=' + escape(document.getElementById('q').value) + '&sa=Search';
                    }
    </script>
    
    <input type="text" name="q" size="31" id="q" style="vertical-align: middle;" />
    <input type="button" onclick="JavaScript:GoogleSiteSerach();" name="sa" value="Search" id="sa" style="vertical-align: middle;" />
    						<img alt="google" src="Graphics/bk/imgB.jpg" style="vertical-align: middle;" />
    
    					</div>


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 20, 2010 11:24 AM
  • User-1712518563 posted

    First, make sure to sign up with "google search for content". !!!Very important!!! Then you can tweek your search from google dashboard. For example you can limit search to only results from your website instead of entire internet, plus you can put adsense links to make money. If try to put google search without actually signing up with them - they will penalize you so bad that no search engine will ever find your site - it will be non existent.

    Also, per Google policy, if you put adsense ads for search results, you can not have any other ads on the results page even other adsense ads. That's why I had to remove my search.aspx from the Master page. If you search on my website - you'll see on results page - there is no any ads except "google for search"

    In the code I gave you above -  in "document.location.href" replace "'http://www.benzonly.com/search.aspx" with URL of your site and create separate page named "Search.aspx" in your root directory. You can modify the style of your Div, but make sure it looks similar to original Google search box with "Google custom search" image in it, because it is required by google.

    Here is image:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 20, 2010 11:49 AM

All replies

  • User-42918493 posted

    Response.Redirect("http://www.admissionhelpline.com/search.aspx?cx=007526145264306847822:l6lp1k1hgi4&cof=FORID%3A9&ie=UTF-8&q=" + txtSearch.Text.Replace("&","and")+"&sa=Search&siteurl=www.admissionhelpline.com%2FgoogleSearch.htm#1024");

    i'm using like this...try this... its working... call this in your search button click event...

    Thursday, May 20, 2010 1:15 AM
  • User-1712518563 posted

    Yes, the problem is: you can not put multiple forms in aspx page. There can be only 1 form. You can solve this problem by building a JavaScript string. That's what I did on my website. You can see how it works by visiting the link in my signature below. I don't want to put a live link for SEO purposes, because this forum is irrelevant to the content of my website. Just copy and paste in the browser - you'll see how it looks. I placed it in the MasterPage.

    However, if you do it using JavaScript - make sure to mimic appearance the way it looks originally with Google Custom Search logo, because you have to adhere to Google policy, otherwise they will penalize you.

    I played here to construct the code: http://code.google.com/apis/ajax/playground/?exp=search#custom_search_control

    I would give you my code, by it creates unique Key. If you have any questions, I can help further.

    Thursday, May 20, 2010 1:32 AM
  • User-1388383071 posted

     simple way to impliment Serch in google i  i am using this code

    response.redirect("http://www.google.co.in/search?hl=en&q="+'txtSearchQuery.text');

    its working for me but i dont know the problems of this .

     

    you can load this page in to your page by using jQuery

    $(document).ready(function()

    {

    $('#btnSearch').click(fucntion()

    {

    var searchString=$('#txtSearchQuery').value;

    $('#divSearchData').load('http://www.google.co.in/search?hl=en&q='+searchString);

    });

    );

    mark if it correct

    Thursday, May 20, 2010 3:01 AM
  • User-1253409855 posted

    Igor, I really like what you did with that search. Is there any way you can help me with the javascript you made?

    I looked and saw

     function GoogleSiteSerach() {
     document.location.href = 'http://www.benzonly.com/search.aspx?cx=partner-pub-9662148617393694%3Aw7wb6i-arla&cof=FORID%3A9&ie=ISO-8859-1&q=' + escape(document.getElementById('q').value) + '&sa=Search';
     } 

    Can you explain that and walk me thru forwarding to a new page?

    Thursday, May 20, 2010 10:45 AM
  • User-1253409855 posted

    wait nevermind I see how that unique string was built and im in the process of getting mine to work

    Thursday, May 20, 2010 10:54 AM
  • User-1253409855 posted

    Maybe it just wont work because my site is local or can i still test it not in production??

    Thursday, May 20, 2010 11:02 AM
  • User-1712518563 posted

    Don't forget to create empty page in your root directory. In my case I called it search.aspx, because when you click search it redirects you to this page. 

    Thursday, May 20, 2010 11:17 AM
  • User-1712518563 posted

     Here is my complete code:

    <div id="search" style="background-color: #000000; text-align: center; ; right: 0px;" >
    						<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
    						<script language="javascript" type="text/javascript">
                    function GoogleSiteSerach() {
                        document.location.href = 'http://www.benzonly.com/search.aspx?cx=partner-pub-9662148617393694%3Aw7wb6i-arla&cof=FORID%3A9&ie=ISO-8859-1&q=' + escape(document.getElementById('q').value) + '&sa=Search';
                    }
    </script>
    
    <input type="text" name="q" size="31" id="q" style="vertical-align: middle;" />
    <input type="button" onclick="JavaScript:GoogleSiteSerach();" name="sa" value="Search" id="sa" style="vertical-align: middle;" />
    						<img alt="google" src="Graphics/bk/imgB.jpg" style="vertical-align: middle;" />
    
    					</div>


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 20, 2010 11:24 AM
  • User-1253409855 posted

    ight benz thanks for your code. is the code on the blank page exactly copied and pasted as well?

    Thursday, May 20, 2010 11:43 AM
  • User-1712518563 posted

    First, make sure to sign up with "google search for content". !!!Very important!!! Then you can tweek your search from google dashboard. For example you can limit search to only results from your website instead of entire internet, plus you can put adsense links to make money. If try to put google search without actually signing up with them - they will penalize you so bad that no search engine will ever find your site - it will be non existent.

    Also, per Google policy, if you put adsense ads for search results, you can not have any other ads on the results page even other adsense ads. That's why I had to remove my search.aspx from the Master page. If you search on my website - you'll see on results page - there is no any ads except "google for search"

    In the code I gave you above -  in "document.location.href" replace "'http://www.benzonly.com/search.aspx" with URL of your site and create separate page named "Search.aspx" in your root directory. You can modify the style of your Div, but make sure it looks similar to original Google search box with "Google custom search" image in it, because it is required by google.

    Here is image:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 20, 2010 11:49 AM
  • User-1712518563 posted

    Also I forgot: replace "cx" value and other values in the long Javascript string with your values from the <form> that google gave you.

    In results - search.aspx page you can copy and paste the code that google gave you originally, because there is no <form> tag in it.

    Here is link to my image: http://www.benzonly.com/Graphics/bk/imgB.jpg

    Thursday, May 20, 2010 12:03 PM
  • User-1253409855 posted

    i got it to work just fine and followed your guidelines. the only thing is the javascript for disabling the logo inside the textbox is not working, i see the logo but its not going away on focus.

    Also do you have to have the other image outside of the textbox?

    Thursday, May 20, 2010 1:01 PM
  • User-1712518563 posted

    Actually, I spent a lot of time trying to make it work, but I could not, and i think its impossible. So I went back to google and generated code with different black layout. You can choose the layout before generating the code. I still could not use the layout itself because of the <form> tag, but at least i got rid of watermark.

    Then i just created the div with black background to mimic the look of original box. That's why I had to place the image outside the search box, because i don't want to ruin relationship with google. 

    Thursday, May 20, 2010 1:28 PM
  • User-1253409855 posted

    Igor, I thank you for helping me. Is there a good way to make your site optimized for searching?

    Thursday, May 20, 2010 4:54 PM
  • User-1712518563 posted

    Thats a big question. There are hundreds of books on SEO. If your site live - I can look at it and give you some suggestions. One thing to remember from ASP.NET point of view: Ajax update panels are the big enemies of SEO. I still use them but trying to minimize, because browsers see inside of panels only what's on loading, but they don't see anything updating - as a result search engines don't see what's inside either and they will never index any keywords or words. The same thing with paging in gridview, formview etc... If you look SourceView in your browser - you'll see content of the 1st page, even if you open it while you are on the 2nd page.

    But don't sacrifice USEABILITY for SEO. If you must use it - use it. Just think of any possible alternatives. Send me a link to your site, if it's live - I'll give you some suggestions.

    Thursday, May 20, 2010 5:17 PM
  • User-1253409855 posted

    Cool, thanks for the information. I was thinking about setting up key words or synonyms. I do have a few update panels. However they are necessary.

    My site is not live at the moment, its live on the company intranet but so far its not done just yet. I appreciate your information and help today you have made this actually work for me.

    Thursday, May 20, 2010 6:22 PM
  • User-261937410 posted

    Good to know that joelkronk was successfully able to place the google search box with javascript code.

    But i see that he was initially trying to have the iFrame version and was not able to get it to work.

    I have myself used the iFrame version on my sites and it works like a charm.

    In case anybody is interested to know about it, you can read this article to make it work for you.

    http://am22tech.com/s/22/Blogs/post/2010/05/26/How-can-I-add-Google-search-box-to-my-website-on-master-page-with-aspnet.aspx

    Thursday, May 27, 2010 10:09 AM
  • User-1712518563 posted

    Good to know that joelkronk was successfully able to place the google search box with javascript code.

    But i see that he was initially trying to have the iFrame version and was not able to get it to work.

    I have myself used the iFrame version on my sites and it works like a charm.

    In case anybody is interested to know about it, you can read this article to make it work for you.

    http://am22tech.com/s/22/Blogs/post/2010/05/26/How-can-I-add-Google-search-box-to-my-website-on-master-page-with-aspnet.aspx

    That can work if you place search box on the white background, but in my case I had to integrate in my Head div, which has picture background. iFrame has set width and height - and you can't match exactly, because in some monitor resolutions, especially when people increase their browser Text size - search box may become covered inside iFrame and then ugly scroll bars appear.

    Plus, it's not very good idea to use iFrame for SEO reasons, because anything inside iFrame is invisible to any search engines. Aslo, there is a study, that explains why pages using Frames get lower PageRank. If you use iFrame in the Master Page - it affects ALL your pages...

    Sunday, May 30, 2010 2:31 PM