Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to access value from custom Web control

How to access value from custom Web control

Scheduled Pinned Locked Moved ASP.NET
helptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    seee sharp
    wrote on last edited by
    #1

    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

    S D 2 Replies Last reply
    0
    • S seee sharp

      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

      S Offline
      S Offline
      seee sharp
      wrote on last edited by
      #2

      I just have to inherit control from INamingContainer regards, - ashish

      1 Reply Last reply
      0
      • S seee sharp

        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

        D Offline
        D Offline
        Dan Satria
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups