(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"));
本文介绍了一个简单的ASP.NET应用程序实例,通过按钮点击事件触发网页跳转至百度搜索页面,并将用户输入的文本框内容作为搜索关键词进行传递。文章详细展示了如何在ASP.NET Web表单中设置按钮和文本框控件,以及如何使用C#代码处理按钮点击事件来实现特定功能。

1082

被折叠的 条评论
为什么被折叠?



