Adding Adsense Search to an ASPX webpage
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.
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.