ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Internet & the Web

Adding Adsense Search to an ASPX webpage

Updated on May 13, 2015

Create ASPX Page

The first step of course is to create an aspx page. I use the free version of Visual Web Developer from Microsoft. Its free and I recommend it. I called my aspx page search.aspx.

As many of you know, Microsoft has done a wonderful job of producing a technology that allows uses to easily create data driven websites. One of the great features of the new technology is master pages, which allows for uniformity on all pages. While this hub is not about master pages, its worth mentioning because in order for a master page to work you must use aspx pages. But I have ran into a problem, and that is just entering the code for a Google AdSense search does not work on an aspx page. But I have come up with a workaround that should work. Let me explain.

The next thing that I did was to create search code from Google. Its real simple and Google walks you through it. They give you the option of searching just the web or of searching other specific web sites for content. For this tutorial I just chose to search the web in general.

I then inserted the Google code into the search.aspx page. I just placed it in the form tags in the code. One thing that you will notice about the Google code is that its encased in a form tag. Your aspx page can only have one form tag on it. This is where the problem arises. If you don't believe me run the page and see it the code works. Interesting enough the search box is displayed but it returns no results.

So what I did next was a trick I picked up while creating my office live website. On that site I discovered that I needed to add a iframe in the html code to be able to view the advertising from AdSense. I decided to use this same logic here. What I did next was just create and .htm page and I called it search.htm (if that is too confusing to have to files with the same name, give it a different name). The next thing I did was then to cut the Google code out of the aspx page and paste it to the htm page.

Then on the aspx page all you simple have to do is add the iframe. The code is very simple:

<iframe src="search.htm" mce_src="search.htm" width="100%" height="100%" frameborder="0" scrolling="no"></iframe>

I set my width and height to 100% just because this page was only intended to be a search page and was not going to have any other content on it. I eliminated the borders by using the frameborder="0" attribute. You also can remove scroll bars by using the scrolling="no" attribute.

The final thing to do is to save both pages and run the aspx page using visual studio. You will see that now the page is a functioning search page.

One other thing to note, don't forget to upload the htm file to a live server - that can cause you some troubles.

Updated 10-16-09

So its been awhile and I thought I would visit this again. I was working on another project and was able to get this exact same thing to work in ASP.Net 3.5. That is good news to those of us who are trying to keep up.


    0 of 8192 characters used
    Post Comment

    • profile image

      website-chef 7 years ago

      hello again,

      your trick worked fine for me in IE.8 and Firefox 3.6.

      but the the search results page still opens in the iFrame for Opera, Google Chrome & Safari.

      any ideas ?

    • profile image

      Website-Chef 7 years ago


      i tried your trick on my website. but the search results page is shown into the iFrame

      i mean the when i click the SEARCH button, the page makes no redirect & the search results page is shown into the iFrame that contains the search box.

      i need help :)

    • runsrealfast profile image

      John 8 years ago from Idaho

      Hey everyone I tried this with .net 3.5 and its still valid. Yeah!

    • runsrealfast profile image

      John 8 years ago from Idaho

      Hi Nam

      Thanks for asking this question. And its a very good one. This functionality you are referring to is actually handled in the setup on the adsense wizard. On the "Search Results Style" step the first question you are asked is

      "Opening of search results page Choose whether you would like your search results to open on Google or within your site."

      On the right you are given three choices:

      Open results on Google in the same window

      Open results on Google in a new window

      Open results within my own site

      This is where you will see that different functionality you are looking for.

      Hope that helps. And once its in production feel free to post your link here.

    • profile image

      Nam 8 years ago


      This solution work, but only for launching the search result in a new page. Can you show me a way display the result in myresult.aspx?


      I did support you by clicking on your advertise.