Add google search box to your web site !!

Karthikreddy
Posted by Karthikreddy under ASP.NET category on | Points: 40 | Views : 1041
design code

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<p>
<br />

<asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Search "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="196px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search in Google" onclick="Button1_Click" />
&nbsp;</p>
<p>
&nbsp;</p>
<p>
</p>
</asp:Content>


code behind


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string text = string.Empty;
StringBuilder textaddress = new StringBuilder();
textaddress.Append("https://www.google.com/search?q=");
if (TextBox1.Text != string.Empty)
{
text = TextBox1.Text.Replace(" ","+");
textaddress.Append(text+""+"+");

}
string url = textaddress.ToString();
Response.Redirect(url, false);

}
catch(Exception ex)
{
Response.Write(ex.ToString());

}
}
}


Comments or Responses

Login to post response