Google Search from ASP.NET

Google Search from ASP.NET

Here by this article we will learn how to search on google based on the query write in textbox

Here is a textbox and a button, write your search text in textbox and click the button, the button redirect you to google with the search result written in textbox…

CODES____

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Google Search</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <asp:Label ID="lbl" runat="server" Width="120px">Google Search...</asp:Label><br />

        <asp:Label ID="Label1" runat="server" ForeColor="Red" Style="z-index: 100; left: 14px;

            position: absolute; top: 95px"></asp:Label>

    <br />

    <asp:TextBox ID="txt" runat="server" Height="19px" Width="293px" ></asp:TextBox>

    <asp:Button ID="btnsearch" runat="server" Text="Search Google" Height="25px" OnClick="btnsearch_Click" Width="137px" />

    </div>

    </form>

</body>

</html>

 

Default.aspx.cs

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }

    protected void btnsearch_Click(object sender, EventArgs e)

    {

        if (txt.Text.Trim().Length == 0)

        {

            Label1.Text = "Please enter text to search";

        }

        else

        {

            Response.Redirect("http://www.google.com/search?q=" + txt.Text);

        }

    }

}

 

 

Interface

asp1.JPG

 

 Thanks

 

Ebook Download
View all
Learn
View all