<%@ Control Language="C#" %><script runat="server">
// GoogleRef.ascx
// written by James Orr, 2003 (jamesorr at hotmail dot com)
// "Share and enjoy!"
// Why bother linking to something when google can do the work for you?
// This user control tokenizes a search string and hits up Google with an
// "I'm Feeling Lucky" search, transparently forwarding the user to the
// "best" result.
//
// - If the parameter "linktype" is set to "search",
// the user gets sent to the google search results.
//
// - if the parameter "searchtext" is included in the tag,
// "href" is displayed as the visible link while "searchtext"
// is passed to google.
//
// usage (register tag at top of file):
// <%@ Register TagPrefix="google" TagName="ref" Src="GoogleRef.ascx" %>
//
// usage (basic):
// <google:ref href="all your base" runat=server />
//
// usage (alternate display text):
// <google:ref searchtext="all your base" href="click here" runat=server />
//
// usage (link to search):
// <google:ref href="all your base" linktype="search" runat=server />
//
// This code may have to be
// updated if Google changes their querystring configuration.
public string href;
public string searchtext="";
public string linktype="";
void Page_Load()
{
// set up local variables for tokenizing the search string
// and build the google URL.
string words;
string linktext;
if(searchtext=="")
{
words = href;
}
else
{
words = searchtext;
}
linktext = "http://www.google.com/search?q=" + words.Replace(' ','+');
// unless the tag contains "linktype=search" use the "I'm feeling Lucky" option.
if(linktype.ToLower()!="search")
{
linktext+="&btnI=Google+Search";
}
// set the anchor and label attributes and we're AUDI 5000
MyAnchor.NavigateUrl = linktext;
MyAnchor.Text = href;
}</script><asp:HyperLink id=MyAnchor runat=server />