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. Creating Textboxes Dynamically

Creating Textboxes Dynamically

Scheduled Pinned Locked Moved ASP.NET
databasealgorithmshelp
6 Posts 6 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.
  • A Offline
    A Offline
    ASPnoob
    wrote on last edited by
    #1

    Hi all, I am trying to create textboxes dynamically and I came across a method that does mostly what I want while searching for a solution on line. The method below is what I've found

    for(int i = 0; i

    The problem with the above code snippet is that sending values placed inside of the created textboxes to a database is difficult because the textboxes all have the same name. If each textbox can be given a different name when it is created, it will be great. Any suggestion is greatly appreciated, thanks in advance

    V V E N R 5 Replies Last reply
    0
    • A ASPnoob

      Hi all, I am trying to create textboxes dynamically and I came across a method that does mostly what I want while searching for a solution on line. The method below is what I've found

      for(int i = 0; i

      The problem with the above code snippet is that sending values placed inside of the created textboxes to a database is difficult because the textboxes all have the same name. If each textbox can be given a different name when it is created, it will be great. Any suggestion is greatly appreciated, thanks in advance

      V Offline
      V Offline
      Vani Kulkarni
      wrote on last edited by
      #2

      Would you please explain how all textboxes have same name. The loop clearly says that every textbox created has index associated with its name. First textbox name reads "TextBoxName1", second reads "TextBoxName2" and so on. Where is the issue you are facing?

      Thanks & Regards, Vani Kulkarni

      1 Reply Last reply
      0
      • A ASPnoob

        Hi all, I am trying to create textboxes dynamically and I came across a method that does mostly what I want while searching for a solution on line. The method below is what I've found

        for(int i = 0; i

        The problem with the above code snippet is that sending values placed inside of the created textboxes to a database is difficult because the textboxes all have the same name. If each textbox can be given a different name when it is created, it will be great. Any suggestion is greatly appreciated, thanks in advance

        V Offline
        V Offline
        vinay_sinha
        wrote on last edited by
        #3

        why dont u provide id of the texbox: tb.ID="txtBox" + i; u just pick id for your any operation.It will be unique. I have replied as much i understand your problem.

        1 Reply Last reply
        0
        • A ASPnoob

          Hi all, I am trying to create textboxes dynamically and I came across a method that does mostly what I want while searching for a solution on line. The method below is what I've found

          for(int i = 0; i

          The problem with the above code snippet is that sending values placed inside of the created textboxes to a database is difficult because the textboxes all have the same name. If each textbox can be given a different name when it is created, it will be great. Any suggestion is greatly appreciated, thanks in advance

          E Offline
          E Offline
          ema2000_t
          wrote on last edited by
          #4

          The problem u have is how to access the dynamically created textboxes, isn't it ok look, the code u had written actually creates a number of objects of type TextBox, and give every one a name that is 'TextBoxName1', 'TextBoxName2',.. etc the problem here is how to access the objects created. so, you must declare a generic dictionary of string and TextBox on the class level, means

          Dictionary AllTextBoxes = new
          Dictionary ();

          this code will be in the class level not inside any methods. the second step is to add a line inside the loop to add items to this dictionary, each of them consists of a key and a value, the key is the name of textbox, while the value is the textbox object created in each loop, this line will be at the end of loop,

          AllTextBoxes.Items.Add("TextBoxName" + i.ToString(), tb);

          now, u can access any textboxe through the dictionary when giving the name of textbox like this

          string aaa = AllTextBoxes["TextBoxName1"].Text;

          I hope this is usefull Dr Sayed Tohamy, Egypt

          1 Reply Last reply
          0
          • A ASPnoob

            Hi all, I am trying to create textboxes dynamically and I came across a method that does mostly what I want while searching for a solution on line. The method below is what I've found

            for(int i = 0; i

            The problem with the above code snippet is that sending values placed inside of the created textboxes to a database is difficult because the textboxes all have the same name. If each textbox can be given a different name when it is created, it will be great. Any suggestion is greatly appreciated, thanks in advance

            N Offline
            N Offline
            n podbielski
            wrote on last edited by
            #5

            For starter I don't think that code you posted above is for asp.net. html TextBox control don't have size and location properties (this is controlled by css class and some css styles). Second, don't you think that placing in a loop with "i" index and appending this index name, give each text box unique name?

            No more Mister Nice Guy... >: |

            1 Reply Last reply
            0
            • A ASPnoob

              Hi all, I am trying to create textboxes dynamically and I came across a method that does mostly what I want while searching for a solution on line. The method below is what I've found

              for(int i = 0; i

              The problem with the above code snippet is that sending values placed inside of the created textboxes to a database is difficult because the textboxes all have the same name. If each textbox can be given a different name when it is created, it will be great. Any suggestion is greatly appreciated, thanks in advance

              R Offline
              R Offline
              RichardGrimmer
              wrote on last edited by
              #6

              Take a look at the properties IsNamingContainer - then tweak how you're adding the text boxes, then FindControl will more than likely look attractive :)

              C# has already designed away most of the tedium of C++.

              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