您的位置:首页 > 其它

怎样在自己的网页中嵌入百度搜索功能

2010-01-28 13:45 459 查看
(1)*.aspx中的代码

<asp:TextBox ID="text1" Runat="server" Width="95px" Height="22" OnTextChanged="text1_TextChanged" ></asp:TextBox>
<asp:Button ID="btn" Text="百度搜索" Runat="server" Width="72px" Height="24" OnClick="btn_Click"></asp:Button>

(2)*.aspx.cs中的代码

protected void btn_Click(object sender, EventArgs e)
{
string texthere = text1.Text;
string searchtext = "http://www.baidu.com/s?wd=" + System.Web.HttpUtility.UrlEncode(texthere, System.Text.UnicodeEncoding.GetEncoding("GB2312")).ToUpper()
+ "&cl=3";
Response.Redirect(searchtext);
}

(3)相关解析

百度的编码:
str = System.Web.HttpUtility.UrlEncode("中文", System.Text.UnicodeEncoding.GetEncoding("GB2312")).ToUpper() ;
百度的解码:
System.Web.HttpUtility.UrlDecode("%C3%CF%CF%DC%BB%E1", System.Text.UnicodeEncoding.GetEncoding("GB2312"));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: