How to access value from custom Web control
-
Hello All, I have created a custom web control. This control contains three different textboxes. I place this control on web form. There is a button on web form. When I click on button, I need to access values of those textboxes. I appreciate if anyone can tell me how to access that value. Appreciate your help. Here is the code for Control. public class MyControl : WebControl { private TextBox textbox1 = new TextBox(); private TextBox textbox2 = new TextBox(); private TextBox textbox3 = new TextBox(); [Category("Appearance")] [DefaultValue("")] [Localizable(true)] [Description("This returns value of textboxes as string")] public string TextBoxChars { get { this.EnsureChildControls(); return this.textbox1.Text + "-" + this.textbox2.Text + "-" + this.textbox3.Text; } } protected override void Render(HtmlTextWriter output) { this.EnsureChildControls(); base.Render(output); } protected override void CreateChildControls() { this.Controls.Clear(); this.Controls.Add(new LiteralControl( "")); this.Controls.Add(new LiteralControl("")); this.Controls.Add(new LiteralControl("")); this.Controls.Add(new LiteralControl("")); this.Controls.Add(new LiteralControl("
")); this.Controls.Add(textbox1); this.Controls.Add(new LiteralControl("
")); this.Controls.Add(textbox2); this.Controls.Add(new LiteralControl("
")); this.Controls.Add(textbox3); this.Controls.Add(new LiteralControl("
")); } } - ashish
-
Hello All, I have created a custom web control. This control contains three different textboxes. I place this control on web form. There is a button on web form. When I click on button, I need to access values of those textboxes. I appreciate if anyone can tell me how to access that value. Appreciate your help. Here is the code for Control. public class MyControl : WebControl { private TextBox textbox1 = new TextBox(); private TextBox textbox2 = new TextBox(); private TextBox textbox3 = new TextBox(); [Category("Appearance")] [DefaultValue("")] [Localizable(true)] [Description("This returns value of textboxes as string")] public string TextBoxChars { get { this.EnsureChildControls(); return this.textbox1.Text + "-" + this.textbox2.Text + "-" + this.textbox3.Text; } } protected override void Render(HtmlTextWriter output) { this.EnsureChildControls(); base.Render(output); } protected override void CreateChildControls() { this.Controls.Clear(); this.Controls.Add(new LiteralControl( "")); this.Controls.Add(new LiteralControl("")); this.Controls.Add(new LiteralControl("")); this.Controls.Add(new LiteralControl("")); this.Controls.Add(new LiteralControl("
")); this.Controls.Add(textbox1); this.Controls.Add(new LiteralControl("
")); this.Controls.Add(textbox2); this.Controls.Add(new LiteralControl("
")); this.Controls.Add(textbox3); this.Controls.Add(new LiteralControl("
")); } } - ashish
I just have to inherit control from INamingContainer regards, - ashish
-
Hello All, I have created a custom web control. This control contains three different textboxes. I place this control on web form. There is a button on web form. When I click on button, I need to access values of those textboxes. I appreciate if anyone can tell me how to access that value. Appreciate your help. Here is the code for Control. public class MyControl : WebControl { private TextBox textbox1 = new TextBox(); private TextBox textbox2 = new TextBox(); private TextBox textbox3 = new TextBox(); [Category("Appearance")] [DefaultValue("")] [Localizable(true)] [Description("This returns value of textboxes as string")] public string TextBoxChars { get { this.EnsureChildControls(); return this.textbox1.Text + "-" + this.textbox2.Text + "-" + this.textbox3.Text; } } protected override void Render(HtmlTextWriter output) { this.EnsureChildControls(); base.Render(output); } protected override void CreateChildControls() { this.Controls.Clear(); this.Controls.Add(new LiteralControl( "")); this.Controls.Add(new LiteralControl("")); this.Controls.Add(new LiteralControl("")); this.Controls.Add(new LiteralControl("")); this.Controls.Add(new LiteralControl("
")); this.Controls.Add(textbox1); this.Controls.Add(new LiteralControl("
")); this.Controls.Add(textbox2); this.Controls.Add(new LiteralControl("
")); this.Controls.Add(textbox3); this.Controls.Add(new LiteralControl("
")); } } - ashish
OnInit() { ... this.textbox1.Text = Request.Form[textbox1.UniqueID].ToString(); ... } or bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) { bool dataChanged = false; if (postDataKey == this.UniqueID) { textbox1.Text = postCollection[textbox1.UniqueID]; Dan Satria Principal Consultant Graha Logica, Inc.