Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > BOOK: ASP.NET Website Programming Problem-Design-Solution
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 16th, 2004, 04:19 PM
Registered User
 
Join Date: Jun 2003
Location: San Francisco, CA, USA.
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
  #2 (permalink)  
Old September 17th, 2004, 09:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
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
  #3 (permalink)  
Old September 17th, 2004, 09:26 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
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
  #4 (permalink)  
Old September 17th, 2004, 03:11 PM
Registered User
 
Join Date: Jun 2003
Location: San Francisco, CA, USA.
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
  #5 (permalink)  
Old September 17th, 2004, 10:05 PM
Registered User
 
Join Date: Jun 2003
Location: San Francisco, CA, USA.
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.
  #6 (permalink)  
Old September 18th, 2004, 10:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
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
  #7 (permalink)  
Old September 20th, 2004, 08:59 PM
Registered User
 
Join Date: Jun 2003
Location: San Francisco, CA, USA.
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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.