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. ArrayList Resetting When Adding Form Controls

ArrayList Resetting When Adding Form Controls

Scheduled Pinned Locked Moved ASP.NET
questiondesignhelp
1 Posts 1 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.
  • R Offline
    R Offline
    redfish34
    wrote on last edited by
    #1

    Below is test code to replicate the problem. I trying to add form controls to an ArrayList. In LinkButton1_Click, two textbox controls are added to ArrayList. No problem. But when i break this code into two separate LinkButtons, only one textbox will ever be added to ArrayList when both link buttons are clicked. The last textbox added will overwrite the first one added. The ArrayList.Add should not behave like this. What is going on? How should i make this work? To store they control i am using an ArrayList. public partial class Builder_Generator : System.Web.UI.Page { ArrayList _controls = new ArrayList(); TextBox _textBox = null; protected void LinkButton1_Click(object sender, EventArgs e) { _textBox = new TextBox(); _textBox.Text = "first"; _textBox.ID = "first_Textbox"; Form_PlaceHolder.Controls.Add(_textBox); _textBox = new TextBox(); _textBox.Text = "second"; _textBox.ID = "second_Textbox"; Form_PlaceHolder.Controls.Add(_textBox); } protected void LinkButton2_Click(object sender, EventArgs e) { _textBox = new TextBox(); _textBox.Text = "first"; _textBox.ID = "first_Textbox"; _controls.Add(_textBox); } protected void LinkButton3_Click(object sender, EventArgs e) { _textBox = new TextBox(); _textBox.Text = "second"; _textBox.ID = "second_Textbox"; _controls.Add(_textBox); } }

    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