LoginControl Bubble Event

ContractedBlock.gif ExpandedBlockStart.gif Add a Bubble Event
  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        pubic method#region pubic method
 17InBlock.gif        public static object _loginEvent = new object();
 18ExpandedSubBlockEnd.gif        #endregion

 19InBlock.gif
 20ContractedSubBlock.gifExpandedSubBlockStart.gif        pulbic event#region pulbic event
 21InBlock.gif        public event EventHandler Login
 22ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 23InBlock.gif            add
 24ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 25InBlock.gif                Events.AddHandler(_loginEvent,value);
 26ExpandedSubBlockEnd.gif            }

 27InBlock.gif            remove
 28ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 29InBlock.gif                Events.RemoveHandler(_loginEvent,value);
 30ExpandedSubBlockEnd.gif            }

 31ExpandedSubBlockEnd.gif        }

 32ExpandedSubBlockEnd.gif        #endregion

 33InBlock.gif
 34ContractedSubBlock.gifExpandedSubBlockStart.gif        要复合的控件#region 要复合的控件
 35InBlock.gif        private TextBox _namecontrol,_passcontrol;
 36InBlock.gif        private Button _loginBtn;
 37ExpandedSubBlockEnd.gif        #endregion

 38InBlock.gif
 39ContractedSubBlock.gifExpandedSubBlockStart.gif        override parent methods#region override parent methods
 40InBlock.gif        protected override HtmlTextWriterTag TagKey
 41ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 42InBlock.gif            get
 43ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 44InBlock.gif                return HtmlTextWriterTag.Table;
 45ExpandedSubBlockEnd.gif            }

 46ExpandedSubBlockEnd.gif        }

 47InBlock.gif        protected override void CreateChildControls()
 48ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 49InBlock.gif            Controls.Clear();
 50InBlock.gif            ClearChildViewState();
 51InBlock.gif            CreateControlHierarchy();
 52InBlock.gif            PrepareControlHierarchy();
 53InBlock.gif            TrackViewState();
 54InBlock.gif            ChildControlsCreated = true;
 55ExpandedSubBlockEnd.gif        }

 56InBlock.gif        protected override void Render(HtmlTextWriter writer)
 57ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 58InBlock.gif            EnsureChildControls();
 59InBlock.gif            base.Render (writer);
 60ExpandedSubBlockEnd.gif        }

 61InBlock.gif        protected override bool OnBubbleEvent(object source, EventArgs args)
 62ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 63InBlock.gif            if(source is Button)
 64ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 65InBlock.gif                OnLogin(null);
 66InBlock.gif                return true;
 67ExpandedSubBlockEnd.gif            }

 68InBlock.gif            return base.OnBubbleEvent (source, args);
 69ExpandedSubBlockEnd.gif        }

 70InBlock.gif        protected virtual void OnLogin(EventArgs args)
 71ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 72InBlock.gif           EventHandler loginhandler = (EventHandler)Events[_loginEvent];
 73InBlock.gif            if(loginhandler != null)
 74ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 75InBlock.gif                loginhandler(this,null);
 76ExpandedSubBlockEnd.gif            }

 77InBlock.gif            else
 78ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 79InBlock.gif                base.RaiseBubbleEvent(this,args);
 80ExpandedSubBlockEnd.gif            }

 81ExpandedSubBlockEnd.gif        }

 82ExpandedSubBlockEnd.gif        #endregion

 83InBlock.gif
 84ContractedSubBlock.gifExpandedSubBlockStart.gif        property (not browsable in property)#region property (not browsable in property)
 85InBlock.gif        [BrowsableAttribute(false)]
 86InBlock.gif        public string userName 
 87ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 88InBlock.gif            get
 89ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 90InBlock.gif                EnsureChildControls();
 91InBlock.gif                return _namecontrol.Text;
 92ExpandedSubBlockEnd.gif            }

 93ExpandedSubBlockEnd.gif        }

 94InBlock.gif        [BrowsableAttribute(false)]
 95InBlock.gif        public string PassWord
 96ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 97InBlock.gif            get
 98ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 99InBlock.gif                EnsureChildControls();
100InBlock.gif                return _passcontrol.Text;    
101ExpandedSubBlockEnd.gif            }

102ExpandedSubBlockEnd.gif        }

103InBlock.gif
104ExpandedSubBlockEnd.gif        #endregion

105InBlock.gif
106ContractedSubBlock.gifExpandedSubBlockStart.gif        private method#region private method
107InBlock.gif        protected virtual void CreateControlHierarchy()
108ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
109InBlock.gif            _namecontrol = new TextBox();
110InBlock.gif            _passcontrol = new TextBox();
111InBlock.gif            _loginBtn = new Button();
112InBlock.gif            _namecontrol.ID = "UserName";
113InBlock.gif            _passcontrol.ID = "PassWord";
114InBlock.gif            _loginBtn.ID = "LoginButton";
115InBlock.gif            _loginBtn.Text = "OK";
116InBlock.gif            ChildControlsCreated = true;
117ExpandedSubBlockEnd.gif        }

118InBlock.gif        protected virtual void PrepareControlHierarchy()
119ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
120InBlock.gif            TableRow row = new TableRow();
121InBlock.gif            TableCell cell = new TableCell();
122InBlock.gif            row.Controls.Add(cell);
123InBlock.gif            cell.Controls.Add(_namecontrol);
124InBlock.gif
125InBlock.gif            cell = new TableCell();
126InBlock.gif            row.Controls.Add(cell);
127InBlock.gif
128InBlock.gif            Controls.Add(row);
129InBlock.gif
130InBlock.gif
131InBlock.gif            row = new TableRow();
132InBlock.gif            cell = new TableCell();
133InBlock.gif            row.Controls.Add(cell);
134InBlock.gif            cell.Controls.Add(_passcontrol);
135InBlock.gif            cell = new TableCell();
136InBlock.gif            row.Controls.Add(cell);
137InBlock.gif            cell.Controls.Add(_loginBtn);
138InBlock.gif            Controls.Add(row);
139ExpandedSubBlockEnd.gif        }

140ExpandedSubBlockEnd.gif        #endregion
  
141ExpandedSubBlockEnd.gif    }

142ExpandedBlockEnd.gif}

143None.gif

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值