关于Web用户控件怎么样读取子控件的值,自定义事件,动态控制子控件状态的应用。
效果图:

/*用户控件界面开始*/
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SearchBar.ascx.cs" Inherits="Singcn.UC.SearchBar" %>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="coolBar">
<tr>
<td style="WIDTH: 3px; CURSOR: move; height: 26px;"><DIV CLASS="TBHandle"></DIV></TD>
<td style="height: 26px">
查询:<asp:TextBox ID="search_txt" runat="server" CssClass="TextBox" Width="120px"></asp:TextBox>
<asp:DropDownList ID="search_lx" runat="server">
</asp:DropDownList>
<asp:Button ID="BOk" runat="server" CssClass="Button" Text="查询" OnClick="BOk_Click"/>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></td>
</tr>
</table>
/*用户控件界面结束*/
/*用户控件代码开始*/
namespace MY.UC
{
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 delegate void BOkClickHandler(object sender, System.EventArgs e); //定义查询按钮委托
//自定义枚举,用户控制查询条显示模式
public enum EBarType { mintype = 1, usertype, xwxxtype };
//1=缺省模式,2=操作员模式,3=新闻管理模式
public partial class SearchBar : System.Web.UI.UserControl
{
public event BOkClickHandler BOkClick;//定义事件
public string SearchTxt//设置文本框内容
{
get { return this.search_txt.Text; }//this.search_txt.Text
set { this.search_txt.Text = value; }
}
private EBarType _BarType;
public EBarType BarType//设置显示模式
{
get { return _BarType; }
set
{
_BarType = value;
switch (value)
{
case EBarType.xwxxtype:
showxwxx();
break;
case EBarType.usertype:
showuser();
break;
default://EBarType.mintype;
showmin();
break;
}
如果您对本文有任何疑问或者建议,请到讨论区发表您的意见:
>>
论坛入口 <<
上一篇:
ASP.NET中上传文件到数据库 下一篇:
cs及前身asp.net forums的调试
【文章评论】
【收藏本文】
【推荐好友】
【打印本文】
【我要投稿】 【论坛讨论】