All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET下载文件时直接弹出“另存为”对话框_[Asp.Net教程]
Visual,C#2005快速入门之声明bool变量_[Asp.Net教程]
随机验证图片的产生,asp.net,2.0,c#,---在网页的特定或莫个位置显示图片_[Asp.Net教程]
Delphi执行sql server区间查询
HTML网页与FLASH之间的传值_[Html教程]
PHPUnit袖珍指南之自动测试_[PHP教程]
C#中的编辑控件(Edit Box)
asp.net2.0网站语法之HTML服务器控件语法
SQL,Server,全局变量_[SQL,Server教程]
如何在十天内学会php之第五天_[PHP教程]
Reading number is top 10 pictures
Sora aoi on twitter1
机器人也有性生活吗?
陪睡门马睿菈自曝写真 称首拍大尺度照片1
Beauty ZhiHuiLin2
More attractive than sora aoi4
教你做读书笔记
30 beautiful school beauty2
妹子最好别玩单反
Absolutely shocked. National geographic 50 animal photographys10
Angie Chiu vijara myth1
Download software ranking
Boxer's Top ten classic battle6
仙剑奇侠传98硬盘WINXP版
VC++6.0培训教程
The Bermuda triangle1
终极变速大师Speeder3.26
少妇苏霞全本
Eclipse 4.2.1 For Win32
I'm come from Beijing1
Tram sex maniac 2 (H) rar bag19
打鸟视频
qq published in(发表于) 2014/7/9 1:38:21 Edit(编辑)
asp.net2.0登陆控件之Login控件应用实例

asp.net2.0登陆控件之Login控件应用实例

asp.net2.0用户控件的应用:站内搜索

站内搜索

对于一些大型的网站,为了方便用户,查询和搜索功能是必不可少的,如果将搜索功能设计成为用户控件,便可以在多个网页中重复使用,从而省去许多重复性的工作。本实例将向读者介绍如何利用用户控件来实现站内查询、搜索功能。实例运行结果如图1和图2所示。



图1  站内搜索用户控件



图2 搜索页传参数

实现过程如下所示。

(1)创建一个Web用户控件menu.ascx,用来实现搜索功能。

(2)创建一个新页SearchInfo.aspx,在该页中添加一个Table表格,用于布局页面。在该Table表格中添加一个已创建好的用户控件menu.ascx,实现查询功能。

(3)主要程序代码。

在Web用户控件menu.ascx上,当用户单击【站内搜索】按钮时,将会触发Button控件的Click事件。将要查询的关键字传递到Search页,代码如下:

protected void cmdSearch_Click(object sender, EventArgs e)

{

Response.Redirect("Search.aspx?str="+this.TextBox1.Text);

}

完整程序代码如下:

★   ★★★★menu.ascx.cs用户控件代码文件完整程序代码★★★★★

using System;

using System.Data;

using System.Configuration;

using System.Collections;

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 WebUserControl : System.Web.UI.UserControl

{

protected void Page_Load(object sender, EventArgs e)

{

Label1.Text = System.DateTime.Now.ToString("yyyy年MM月dd日") + "   " + System.DateTime.Now.DayOfWeek.ToString();

}

protected void cmdSearch_Click(object sender, EventArgs e)

{

Response.Redirect("search.aspx?Str="+this.TextBox1.Text);

}

}

★   ★★★★menu.ascx用户控件设计文件完整程序代码★★★★★

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="menu.ascx.cs" Inherits="WebUserControl" %>

<table style="width: 801px; height: 18px; font-size: 10pt; color: #000099; margin-top: 0px; padding-top: 0px;" class="css" border="0" cellspacing="0">

<tr>

<td align="right" colspan="10" style="background-image: url(image/1.gif); height: 28px">

 

  

<asp:Label ID="Label1" runat="server" Text="Label" Width="200px" ForeColor="White"></asp:Label> </td>

</tr>

<tr>

<td align="right" colspan="10" style="background-image: url(image/2.gif); color: #ffff66;

height: 7px" class="txt">

输入关键字:  

<asp:TextBox ID="TextBox1" runat="server" Width="240px" Height="17px"></asp:TextBox> 

<asp:DropDownList ID="DropDownList1" runat="server" Width="78px" CssClass="txt" Height="3px">

<asp:ListItem>时政要闻</asp:ListItem>

<asp:ListItem>环境保护</asp:ListItem>

<asp:ListItem>招商信息</asp:ListItem>

<asp:ListItem>科学教育</asp:ListItem>

<asp:ListItem>法治频道</asp:ListItem>

<asp:ListItem>社会现象</asp:ListItem>

<asp:ListItem>股市信息</asp:ListItem>

<asp:ListItem>时尚娱乐</asp:ListItem>

</asp:DropDownList>

<asp:Button ID="cmdSearch" runat="server" Text="站内搜索" OnClick="cmdSearch_Click" Height="20px" />

     </td>

</tr>

<tr>

<td align="center" rowspan="1" style="background-image: url(image/301.gif); width: 151px;">

</td>

<td align="center" style="background-image: url(image/302.gif); width: 72px;">

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/newsList.aspx?id=News" Font-Underline="False" ForeColor="#333333">主页</asp:HyperLink></td>




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.