ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Adding Adsense Search to an ASPX webpage

Updated on February 14, 2018

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.

© 2008 John


    0 of 8192 characters used
    Post Comment
    • profile image


      8 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


      8 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 imageAUTHOR


      9 years ago from Idaho

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

    • runsrealfast profile imageAUTHOR


      9 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


      9 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.


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)