LoginControl

一个简单的复合控件的例子,从中尝到不少。。
ContractedBlock.gif ExpandedBlockStart.gif LoginControl
  1None.gifusing System;
  2None.gifusing System.Collections;
  3None.gifusing System.Collections.Specialized;
  4None.gifusing System.ComponentModel;
  5None.gifusing System.Web;
  6None.gifusing System.Web.UI;
  7None.gifusing System.Web.UI.WebControls;
  8None.gif
  9None.gifnamespace PowerAsp.NET.Comtrols
 10ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 11ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
 12InBlock.gif    /// 复合控件例子。
 13ExpandedSubBlockEnd.gif    /// </summary>      

 14InBlock.gif    public class LoginControl : System.Web.UI.WebControls.WebControl,INamingContainer
 15ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 16ContractedSubBlock.gifExpandedSubBlockStart.gif        要复合的控件#region 要复合的控件
 17InBlock.gif        private TextBox _namecontrol,_passcontrol;
 18InBlock.gif        private Button _loginBtn;
 19ExpandedSubBlockEnd.gif        #endregion

 20InBlock.gif
 21ContractedSubBlock.gifExpandedSubBlockStart.gif        override parent methods#region override parent methods
 22InBlock.gif        protected override HtmlTextWriterTag TagKey
 23ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 24InBlock.gif            get
 25ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 26InBlock.gif                return HtmlTextWriterTag.Table;
 27ExpandedSubBlockEnd.gif            }

 28ExpandedSubBlockEnd.gif        }

 29InBlock.gif        protected override void CreateChildControls()
 30ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 31InBlock.gif            Controls.Clear();
 32InBlock.gif            ClearChildViewState();
 33InBlock.gif            CreateControlHierarchy();
 34InBlock.gif            PrepareControlHierarchy();
 35InBlock.gif            TrackViewState();
 36InBlock.gif            ChildControlsCreated = true;
 37ExpandedSubBlockEnd.gif        }

 38InBlock.gif        protected override void Render(HtmlTextWriter writer)
 39ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 40InBlock.gif            EnsureChildControls();
 41InBlock.gif            base.Render (writer);
 42ExpandedSubBlockEnd.gif        }
                         
 43ExpandedSubBlockEnd.gif        #endregion

 44InBlock.gif
 45ContractedSubBlock.gifExpandedSubBlockStart.gif        property (not browsable in property)#region property (not browsable in property)
 46InBlock.gif        [BrowsableAttribute(false)]
 47InBlock.gif        public string userName 
 48ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 49InBlock.gif            get
 50ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 51InBlock.gif                EnsureChildControls();
 52InBlock.gif                return _namecontrol.Text;
 53ExpandedSubBlockEnd.gif            }

 54ExpandedSubBlockEnd.gif        }

 55InBlock.gif        [BrowsableAttribute(false)]
 56InBlock.gif        public string PassWord
 57ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 58InBlock.gif            get
 59ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 60InBlock.gif                EnsureChildControls();
 61InBlock.gif                return _passcontrol.Text;    
 62ExpandedSubBlockEnd.gif            }

 63ExpandedSubBlockEnd.gif        }

 64InBlock.gif
 65ExpandedSubBlockEnd.gif        #endregion

 66InBlock.gif
 67ContractedSubBlock.gifExpandedSubBlockStart.gif        private method#region private method
 68InBlock.gif        protected virtual void CreateControlHierarchy()
 69ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 70InBlock.gif            _namecontrol = new TextBox();
 71InBlock.gif            _passcontrol = new TextBox();
 72InBlock.gif            _loginBtn = new Button();
 73InBlock.gif            _namecontrol.ID = "UserName";
 74InBlock.gif            _passcontrol.ID = "PassWord";
 75InBlock.gif            _loginBtn.ID = "LoginButton";
 76InBlock.gif            _loginBtn.Text = "OK";
 77InBlock.gif            ChildControlsCreated = true;
 78ExpandedSubBlockEnd.gif        }

 79InBlock.gif        protected virtual void PrepareControlHierarchy()
 80ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 81InBlock.gif            TableRow row = new TableRow();
 82InBlock.gif            TableCell cell = new TableCell();
 83InBlock.gif            row.Controls.Add(cell);
 84InBlock.gif            cell.Controls.Add(_namecontrol);
 85InBlock.gif
 86InBlock.gif            cell = new TableCell();
 87InBlock.gif            row.Controls.Add(cell);
 88InBlock.gif
 89InBlock.gif            Controls.Add(row);
 90InBlock.gif
 91InBlock.gif
 92InBlock.gif            row = new TableRow();
 93InBlock.gif            cell = new TableCell();
 94InBlock.gif            row.Controls.Add(cell);
 95InBlock.gif            cell.Controls.Add(_passcontrol);
 96InBlock.gif            cell = new TableCell();
 97InBlock.gif            row.Controls.Add(cell);
 98InBlock.gif            cell.Controls.Add(_loginBtn);
 99InBlock.gif            Controls.Add(row);
100ExpandedSubBlockEnd.gif        }

101ExpandedSubBlockEnd.gif        #endregion
  
102ExpandedSubBlockEnd.gif    }

103ExpandedBlockEnd.gif}

104None.gif

转载于:https://www.cnblogs.com/nanshouyong326/archive/2006/12/21/599301.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值