Wrox Programmer Forums
|
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 16th, 2004, 04:19 PM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Google Adsense for Search script in asp.net page

I am trying to use a Google "Adsense for Search" box on my asp.net page. I eventually want to put it in my SiteHeader control, within a table that I can make invisible based on certain criteria. For now, I'm just put in in default.aspx to try to get it to work. The problem is the code Google provides includes "<form method="get" action="http://www.google.com/custom" target="google_window">". That won't work in a asp.net page. I found a way around this for my Paypal donate button and I tried to copy that method. I removed the form tags. Instead, I added the following JavaScript code:

        <SCRIPT language="javascript">


        function SubmitForm()
        {

            var frm = document.forms[0];

                frm.action="http://www.google.com/custom";
            frm.target="google_window";
            frm.submit();
        }

        </SCRIPT>

On the search button i add : onclick="SubmitForm()".

When I click the search button, It goes to the Google page but with an error which says "Not Implemented. The server is unable to process your request." I think that maybe Google is not able to get the hidden fields on my page but it works fine with the PayPal button.

Any suggestions?

Claude
ClaudesPlace.com
 
Old September 17th, 2004, 09:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You probably need to do your own submit using either xmlhttp on the client (requires Windows and IE 5+ on users computer), or the WebRequest object on the server.

I understand that Mozilla browsers let you do this with createDocument in Javascript, but I don't know much about this.

Here's some links:
http://aspnetforum.dyndns.org/myASPX...px?i=9&j=20410
http://support.microsoft.com/default...NoWebContent=1
http://authors.aspalliance.com/steve.../netscrape.asp
http://www.aspxfiles.com/default.asp...lCSharp?diff=y
http://www.dotnet247.com/247referenc...47/237532.aspx

The code at the bottom of this page is where I'd start to make a simple console mode program as a proof of concept:
http://www.csharpfriends.com/Forums/...x?PostID=19409

He encoded his own values in his postData string, but you could also use HttpUtility.UrlEncode to do that for you.

Eric
 
Old September 17th, 2004, 09:26 AM
Authorized User
 
Join Date: Jul 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Claude,
         I created a Google Site Search User Control, and added the following HTML:
//-----------------------------------------------------------

<table border="0" bgcolor="#ffffff" style="WIDTH: 309px; HEIGHT: 40px">
    <tr>
        <td nowrap valign="top" align="left" height="32">
            <p><A href="http://www.google.com/"><img SRC="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google"></A></p>
        </td>
        <td><p>
                <asp:TextBox id="txtSearch" runat="server" CssClass="textboxGoogle"></asp:TextBox>&nbsp;<asp:Button id="btnSearchGoogle" runat="server" Text="Search" CausesValidation="False" CssClass="Button"></asp:Button></p>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <p style="MARGIN-LEFT: 75px"><asp:RadioButtonList id="radbtnlstGoogle" runat="server" RepeatDirection="Horizontal" Font-Size="11px">
                    <asp:ListItem Value="Web">Web</asp:ListItem>
                    <asp:ListItem Value="MySite" Selected="True">MySite</asp:ListItem>
                </asp:RadioButtonList></p>
        </td>
    </tr>
</table>

//---------------------------------------------------------

Then in the code behind add this to the btnSearchGoogle event, note you will have to figure out the correct google urls string for your site:

    private void btnSearchGoogle_Click(object sender, System.EventArgs e)
        {
            if(radbtnlstGoogle.Items[radbtnlstGoogle.SelectedIndex].Text == "MySite")
            {
                Response.Redirect("http://www.google.com/custom?domains=MySite.com&q=" + txtSearch.Text + "&sa=Search&sitesearch=MySite.com&client=pub-4&ford=1&channel=70891&ie=ISO-8859-1&oe=ISO-8859-1&cof=GALT%3A%%3%%3A%2F%2Fwww.mysite.com%2FImages% 2FGoogle01.gif%3BS%3Ahttp%3A%2F%2Fwww.mysite.com%3 BFORID1%3B&hl=en");
            }
            else
            {
            Response.Redirect("http://www.google.com/custom?domains=mysite.com&q=" + txtSearch.Text + "&sa=Search&sitesearch=&client=pub-&forid=1&channel=91&ie=ISO-8859-1&oe=ISO-8859-1&cof=GALT%3A%3A%%3BL%3Ahttp%3A%2F%2Fwww.mysite.co m%2FImages%2FGoogle01.gif%3BS%3Ahttp%3A%2F%2Fwww.m ysite.com%3BFO1%3B&hl=en");
            }
        }


Hope this helps,
d
 
Old September 17th, 2004, 03:11 PM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the replies. Are you sure you want to include all those fields in a query string that the user can see? I'm not sure what all those fields mean, but the client field (pub-xxxx) looks like an account identifier. I'm not sure Google would want that made public. They should, of course, provide code for .NET users so we don't have to come up with our own solutions. I've sent them an email. Meanwhile I will check out the ideas in the first reply. When I get it working I'll post the final solution.


Thanks,


Claude
ClaudesPlace.com
 
Old September 17th, 2004, 10:05 PM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by claudew
 Thanks for the replies. Are you sure you want to include all those fields in a query string that the user can see? I'm not sure what all those fields mean, but the client field (pub-xxxx) looks like an account identifier. I'm not sure Google would want that made public. They should, of course, provide code for .NET users so we don't have to come up with our own solutions. I've sent them an email. Meanwhile I will check out the ideas in the first reply. When I get it working I'll post the final solution.

Well I was wrong about not showing the query string. That is exactly what happens when you click the search button with their code. The response I got back from Google was that it is a violation of their policy to modify their code in any way. They suggested putting it outside of my Form tag, either above or below. It works, but it leaves me with no way to control the location of the box or to put it in a user control such as SiteHeader so I have to manually put it on every page. developerz - I like your user control but I'm afraid to use it since they will now be checking my site.
 
Old September 18th, 2004, 10:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Beware of ViewState in your page that uses Adsense. You may need to disable it:

http://scottonwriting.net/sowblog/posts/1323.aspx

Eric
 
Old September 20th, 2004, 08:59 PM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by englere
 Beware of ViewState in your page that uses Adsense. You may need to disable it:

http://scottonwriting.net/sowblog/posts/1323.aspx

Eric
I found that article too in my searches to find a solution to this problem. However, just as with the Adsense for Search, I am not willing to give up the benefits of .NET. I'm using Adsense on most pages. I used my dial-up account to check and see if ViewState slowed things down too much for dial-up users and it didn't.

For their free Google search box they provide Web APIs. I suspect they will eventually offer that option for Adsense and Adsense for Search. I got a much more positive reply back from Google today stating that Adsense was a new program and that they would pass my comments about ASP.NET on to their team.

Meanwhile, I've decided to use Application_BeginRequest in Global.asax.cs to output the Google code if certain conditions are met. Although I can't control where the box appears (it appears at the top of the page - or the bottom if I use Application_EndRequest), at least I can control when it appears programmatically.

Claude
ClaudesPlace.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Google search with Java jvlaine Java Basics 3 December 15th, 2007 03:08 AM
INFO: Adding Google Maps (New ASP.Net Control) jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 September 12th, 2007 03:18 AM
Google-like SQL search jemaj21 Access VBA 2 April 7th, 2006 09:52 PM
How can I search at Yahoo or Google ? bapechun Classic ASP Basics 1 March 26th, 2004 11:08 PM
asp search page help. kyootepuffy Classic ASP Databases 4 September 9th, 2003 10:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.