How to use CreateChildContorls method inherited from System.Web.UI.Control

博客介绍在创建ASP.Net控件时,应重写CreateChildControls方法,在其中实例化控件、设置属性、创建事件处理程序并添加到控件集合,最后可重写RenderWebPart方法绘制输出,还给出了C#中CreateChildControls方法的部分代码示例。
    *** The CreateChildControls Method ***

    When you create any ASP.Net controls in a web part, you should override the CreateChildControls method. In the CreateChildControls method, you will instantiate each control, set its properties, create any necessary event handlers, and add the created child controls to the web part's Controls collection inherited from System.Web.UI.Control.

    Finally, you can draw the output by overriding the RenderWebPart method.
    The following codes shows a portion of the CreateChildControls method in C#.
None.gif   protected Label lbError;
None.gif   
protected Label lbCustomerId;
ExpandedBlockStart.gifContractedBlock.gif   
/**//// <summary>
InBlock.gif   
///  CreateChildControls
InBlock.gif   
///  Override CreateChildControls to add
InBlock.gif   
///  child ASP.NET controls to this Web Part.
ExpandedBlockEnd.gif   
/// </summary>

None.gif   protected override void CreateChildControls()
ExpandedBlockStart.gifContractedBlock.gif   
dot.gif{
InBlock.gif      
//Lable that display error messages
InBlock.gif
      lbError = new Label();
InBlock.gif      lbError.Visible 
= false;
InBlock.gif      lbError.ForeColor 
= Color.Red;
InBlock.gif      Controls.Add(lbError);   
//Add to controls list
InBlock.gif   
InBlock.gif      
//Lable that display Customer Id
InBlock.gif
      lbCustomerId =  new Label();
InBlock.gif      lbCustomerId.Visible 
= false;
InBlock.gif      Controls.Add(lbCustomerId);   
//Add to controls list
ExpandedBlockEnd.gif
   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值