<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ★33°空間‰


                           ----★七彩服飾  【最潮拜☆日單精品】【Esprit】【Hotwind】滿150包郵-女裝-流行女裝    www.7color.hb.cn

                           ----智力比知識重要,素質比智力重要,覺悟比素質更重要
    posts - 110,comments - 35,trackbacks - 0

    本人學習.net用戶控件的過程:如何讀取子控件的值,自定義事件,動態(tài)控制子控件的狀態(tài),附帶例子。

    關于Web用戶控件如何讀取子控件的值,自定義事件,動態(tài)控制子控件狀態(tài)的應用。

    效果圖:

    ?

    /*用戶控件界面開始*/

    <%@ 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">
    ??????? &nbsp;查詢:<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;
    ??????????????? }

    ??????????? }
    ??????? }
    ???
    ???
    ??????? private bool _TxtVisible;
    ??????? public bool TxtVisible
    ??????? {
    ??????????? get { return _TxtVisible; }
    ??????????? set
    ??????????? {
    ??????????????? _TxtVisible = value;
    ??????????????? this.search_txt.Visible = _TxtVisible;
    ??????????? }
    ??????? }//控制文本框是否顯示

    ??????? private bool _LXVisible;
    ??????? public bool LXVisible
    ??????? {
    ??????????? get { return _LXVisible; }
    ??????????? set
    ??????????? {
    ??????????????? _LXVisible = value;
    ??????????????? this.search_lx.Visible = _LXVisible;
    ??????????? }
    ??????? }//控制下拉列表是否顯示

    ???????
    ??????? //private string _SearchLX;
    ??????? public string SearchLX
    ??????? {
    ??????????? get { return this.search_lx.SelectedItem.Value; }//this.search_lx.SelectedItem.Value;_SearchLX
    ??????????? set
    ??????????? {
    ??????????????? for (int myi = 0; myi < search_lx.Items.Count ; myi++)
    ??????????????? {
    ??????????????????? if (search_lx.Items[myi].Value == value)
    ??????????????????? {
    ??????????????????????? search_lx.SelectedIndex = myi;
    ??????????????????????? break;
    ??????????????????? }
    ??????????????? }
    ??????????? }
    ??????? }//設置下拉列表的值

    ??????? protected void Page_Load(object sender, EventArgs e)
    ??????? {

    ??????? }

    ??????? #region web 窗體設計器生成的代碼
    ??????? override protected void OnInit(EventArgs e)
    ??????? {
    ??????????? InitializeComponent();
    ??????????? base.OnInit(e);

    ??????? }

    ??????? private void InitializeComponent()
    ??????? {
    ??????????? this.BOk.Click += new System.EventHandler(this.BOk_Click);//這一行很重要
    ??????? }
    ??????? #endregion

    ??????? protected void BOk_Click(object sender, EventArgs e)
    ??????? {
    //??????????? this._SearchTxt = this.search_txt.Text;
    ??????????? //this._SearchLX = this.search_lx.SelectedItem.Value;
    ??????????? if (BOkClick != null)
    ??????????????? BOkClick(this, e);
    ??????? }

    ??????? private void showxwxx()//新聞管理模式的界面處理
    ??????? {
    ??????????? Label1.Visible = false;
    ??????????? search_txt.Visible = true;
    ??????????? search_lx.Visible = true;
    ??????????? search_lx.Items.Clear();
    ??????????? ListItem myitem = new ListItem();
    ??????????? myitem.Text = "標題";
    ??????????? myitem.Value = "1";
    ??????????? search_lx.Items.Add(myitem);
    ??????????? myitem = new ListItem();
    ??????????? myitem.Text = "作者";
    ??????????? myitem.Value = "2";
    ??????????? search_lx.Items.Add(myitem);
    ??????????? search_lx.SelectedIndex = 0;
    ???????
    ??????? }
    ??????? private void showuser()//操作員模式的界面處理
    ??????? {
    ??????????? Label1.Visible = false;
    ??????????? search_txt.Visible = true;
    ??????????? search_lx.Visible = true;
    ??????????? search_lx.Items.Clear();
    ??????????? ListItem myitem = new ListItem();
    ??????????? myitem.Text="用戶ID";
    ??????????? myitem.Value="1";
    ??????????? search_lx.Items.Add(myitem);
    ??????????? myitem = new ListItem();
    ??????????? myitem.Text = "用戶名稱";
    ??????????? myitem.Value = "2";
    ??????????? search_lx.Items.Add(myitem);
    ??????????? search_lx.SelectedIndex = 0;

    ??????? }

    ??????? private void showmin()//缺省模式的界面處理
    ??????? {
    ??????????? Label1.Visible = true;
    ??????????? search_txt.Visible = true;
    ??????????? search_lx.Visible = false;
    ??????????? search_lx.Items.Clear();


    ??????? }
    ??? }
    }
    /*用戶控件代碼結束*/

    /*測試頁界面開始*/

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="SearchBarTest.aspx.cs" Inherits="Control_SearchBarTest" %>

    <%@ Register Src="SearchBar.ascx" TagName="SearchBar" TagPrefix="uc1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    ??? <title>無標題頁</title>
    ??? <link href="../CSS/system.css" _fcksavedurl=""../CSS/system.css"" _fcksavedurl=""../CSS/system.css"" _fcksavedurl=""../CSS/system.css"" rel="stylesheet" type="text/css" />
    ???
    ??? <link href="../CSS/searchbar.css" rel="stylesheet" type="text/css" />???
    </head>
    <body>
    ??? <form id="form1" runat="server">
    ??? <div>
    ??????? <uc1:SearchBar ID="SearchBar1" runat="server" BarType="usertype" />
    ??????? <asp:Label ID="Label1" runat="server" Text="查詢結果"></asp:Label><br />
    ??????? <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="缺省" />
    ??????? <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="操作員界面" />
    ??????? <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="新聞管理界面" />
    ??????? <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="隱藏下拉框" /></div>
    ??????? <br />
    ??? </form>
    </body>
    </html>
    /*測試頁界面結束*/

    /*測試頁代碼開始*/

    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;
    using MY.UC;

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

    ??? }

    ??? #region web 窗體設計器生成的代碼
    ??? override protected void OnInit(EventArgs e)
    ??? {
    ??????? InitializeComponent();
    ??????? base.OnInit(e);
    ??? }

    ??? private void InitializeComponent()
    ??? {
    ??????? //注冊查詢條的按鈕事件
    ??????? this.SearchBar1.BOkClick += new BOkClickHandler(this.SearchBar1_BOkClick);

    ??? }
    ??? #endregion

    ??? protected void SearchBar1_BOkClick(object sender, EventArgs e)
    ??? {
    ??????? //查詢按鈕事件
    ??????? Label1.Text = "查詢內容:"+this.SearchBar1.SearchTxt +"? 選擇列表:"+ this.SearchBar1.SearchLX;

    ??? }
    ??? protected void Button1_Click(object sender, EventArgs e)
    ??? {
    ??????? this.SearchBar1.BarType = EBarType.mintype;
    ??? }

    ??? protected void Button2_Click(object sender, EventArgs e)
    ??? {
    ??????? this.SearchBar1.BarType = EBarType.usertype;
    ??? }

    ??? protected void Button3_Click(object sender, EventArgs e)
    ??? {
    ??????? this.SearchBar1.BarType = EBarType.xwxxtype;
    ??? }

    ??? protected void Button4_Click(object sender, EventArgs e)
    ??? {
    ??????? this.SearchBar1.LXVisible = false;
    ??? }
    }


    /*測試頁代碼結束*/

    posted on 2007-03-23 10:35 圣域飛俠 閱讀(1013) 評論(0)  編輯  收藏 所屬分類: 轉載
    主站蜘蛛池模板: 99人中文字幕亚洲区| 亚洲一区免费在线观看| 免费国产黄网站在线观看 | 免费无码VA一区二区三区| 亚洲成a人片7777| 国产美女无遮挡免费网站| 两个人看的www高清免费视频| 亚洲视频免费一区| 国产一卡二卡3卡四卡免费| 亚洲精品无码国产片| 59pao成国产成视频永久免费| 国产精品亚洲综合久久| 91麻豆精品国产自产在线观看亚洲| 99久久免费精品视频| 牛牛在线精品免费视频观看| 久久久久亚洲av无码专区| 四虎www成人影院免费观看| 波多野结衣免费一区视频| 亚洲精品无码久久久久秋霞| 亚洲日韩欧洲乱码AV夜夜摸| 免费观看理论片毛片| 91精品导航在线网址免费| 亚洲大尺度无码无码专区| 永久久久免费浮力影院| 日韩电影免费在线观看中文字幕| 亚洲狠狠婷婷综合久久| 国产片免费福利片永久| 91精品啪在线观看国产线免费| 看一级毛片免费观看视频| 亚洲va在线va天堂va手机| 亚洲成色WWW久久网站| 日韩亚洲精品福利| 妞干网免费观看视频| 久99久精品免费视频热77| 欧亚一级毛片免费看| 亚洲6080yy久久无码产自国产| 亚洲高清视频在线播放| 国产亚洲婷婷香蕉久久精品| 亚洲国产精品第一区二区三区| 亚洲乱人伦中文字幕无码| 麻豆亚洲AV永久无码精品久久|