Live Chat Icon For mobile
Live Chat Icon

How can you create a check box dynamically in the server control?

Platform: ASP.NET| Category: Custom Controls
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Text;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;

namespace WebCustomControl1
{
	[DefaultProperty('Text')]
	[ToolboxData('<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>')]
	public class WebCustomControl1 : WebControl
	{
		[Bindable(true)]
		[Category('Appearance')]
		[DefaultValue('')]
		[Localizable(true)]
		public string Text
		{
			get
			{
				String s = (String)ViewState['Text'];
				return ((s == null) ? String.Empty : s);
			}
			set
			{
				ViewState['Text'] = value;
			}
		}
		
		protected override void CreateChildControls()
		{
			CheckBox blah = new CheckBox();
			blah.Text = 'CheckText';
			blah.ID = 'CheckValue';
			this.Controls.Add(blah);
		}
	
		protected override void RenderContents(HtmlTextWriter writer)
		{
			this.EnsureChildControls();
			this.RenderChildren(writer);
		}
    	}
}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.