ASP.NET 2.0服务器控件之复合控件概述
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-05-22
ameValidator.ErrorMessage; } set { EnsureChildControls(); nameValidator.ErrorMessage = value; nameValidator.ToolTip = value; } } // 实现属性NameLabelText [ Bindable(true), Category("Appearance"), DefaultValue(""), Description("用户名文本框旁的文字.") ] public string NameLabelText { get { EnsureChildControls(); return nameLabel.Text; } set { EnsureChildControls(); nameLabel.Text = value; } } // 实现属性Email [ Bindable(true), Category("Default"), DefaultValue(""), Description("邮件地址.") ] public string Email { get { EnsureChildControls(); return emailTextBox.Text; } set { EnsureChildControls(); emailTextBox.Text = value; } } // 实现属性EmailErrorMessage [ Bindable(true), Category("Appearance"), DefaultValue(""), Description("邮件地址验证错误信息.") ] public string EmailErrorMessage { get { EnsureChildControls(); return emailValidator.ErrorMessage; } set { EnsureChildControls(); emailValidator.ErrorMessage = value; emailValidator.ToolTip = value; } } // 实现属性EmailLabelText [ Bindable(true), Category("Appearance"), DefaultValue(""), Description("电子邮件文本框旁的文字.") ] public string EmailLabelText { get { EnsureChildControls(); return emailLabel.Text; } set { EnsureChildControls(); emailLabel.Text = value; } } // 重写ICompositeControlDesignerAccessor接口的RecreateChildContrls方法 protected override void RecreateChildControls() { EnsureChildControls(); } // 重写Control基类的CreateChildControls方法 protected override void CreateChildControls() { // 清除所有子控件 Controls.Clear(); nameLabel = new Label(); nameTextBox = new TextBox(); nameTextBox.ID = "nameTextBox"; nameValidator = new RequiredFieldValidator(); nameValidator.ID = "validator1"; nameValidator.ControlToValidate = nameTextBox.ID; nameValidator.Text = NameErrorMessage; nameValidator.Display = ValidatorDisplay.Static; emailLabel = new Label(); emailTextBox = new TextBox(); emailTextBox.ID = "emailTextBox"; emailValidator = new RequiredFieldValidator(); emailValidator.ID = "validator2"; emailValidator.ControlToValidate = emailTextBox.ID; emailValidator.Text = EmailErrorMessage; emailValidator.Display = ValidatorDisplay.Static; submitButton = new Button(); submitButton.ID = "button1"; this.Controls.Add(nameLabel); this.Controls.Add(nameTextBox); this.Controls.Add(nameValidator); this.Controls.Add(emailLabel); this.Controls.Add(emailTextBox); this.Controls.Add(emailValidator); this.Controls.Add(submitButton); } // 重写Render方法 protected override void Render(HtmlTextWriter writer) { AddAttributesToRender(writer); writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "1", false); |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于ASP.NET 2.0服务器控件之复合控件概述的所有评论