How to use dynamically generated TextBox's in a Wizard

Last post 06-17-2008 11:57 AM by smexcellence. 7 replies.

Sort Posts:

  • How to use dynamically generated TextBox's in a Wizard

    04-03-2006, 11:29 PM
    • Loading...
    • Andles
    • Joined on 01-04-2006, 7:26 AM
    • Posts 56

    I have a 4 step wizard. Step 1 asks a user to enter a test (exam) question and then asks them to choose how many answers to create. Step 2 of the wizard will then generate the neccasarry number of TextBox's, as per the quantity entered by the user.

    Now on step 3 of the wizard, I have access to the answers only via the 'Request' collection but not via the control tree. No doubt becuase the answer TextBoxes are no longer part of the control tree due to them being built only once.

    My first thoughts were to create a hidden field of some kind (or use view state), and store all answers in this control. This control would then be around for step 4 of the wizard, where I then do something with the data accumulated across all  wizard steps.

    Two questions - am I solving this problem correctly? It seems rather awkward to be a good solution. And, are there any pointers or good resources for working with dynamically generated controls. I don't quite get why such a great feature would have such a limitation - when I submit my dynamic controls I want to be able to see them as controls on the server and not have to use 'Request' object.

  • Re: How to use dynamically generated TextBox's in a Wizard

    04-04-2006, 5:05 AM
    • Loading...
    • Andles
    • Joined on 01-04-2006, 7:26 AM
    • Posts 56

    Well, I just found out the following:

    " Note When you create dynamic controls on a Web Form, you must create the controls and add them to the controls collection in either the Page_Init event handler or the Page_Load event handler. Otherwise, the controls may not behave as expected."

    My controls are being created within the wizard event "ActiveStepChanged" - so is this why I cannot access ther values via the control tree? If so, what do I need to do to solve this problem when I MUST build dyamic controls based on teh active index of wizard control?

    Is this just a limitation of the wizard control??

     

     

  • Re: How to use dynamically generated TextBox's in a Wizard

    08-25-2006, 2:46 AM
    • Loading...
    • shmick
    • Joined on 02-28-2006, 2:58 AM
    • Posts 12
    Yeah, I am having the same problem. Anyone found a solution for this yet or can point us in the right direction??
  • Re: How to use dynamically generated TextBox's in a Wizard

    09-11-2006, 4:29 PM
    • Loading...
    • Nakkii
    • Joined on 09-11-2006, 8:25 PM
    • Posts 1

    Oh, I hate doing this: "Me too" I have been fighting this for the better part of two days now, read tens of posts and articles and I get the "Page_init", "Page_load" viewstate issue, but what I don't get is how to handle it in the wizard.

     I am asking for number of locations and then the next step is asking for the addresses (dynamically created controls for each location). and then in several steps later I want to store the info, but the cotrols are gone.

     Idea: Do you need to create an array and the save the values to the array in the wizards "nextbuttonclick" event?

  • Re: How to use dynamically generated TextBox's in a Wizard

    09-11-2006, 10:40 PM
    • Loading...
    • MilanNegovan
    • Joined on 01-04-2004, 6:20 PM
    • Long Island, NY
    • Posts 296
    • TrustedFriends-MVPs

    Folks, I've put together a sample project for you which demonstrates how to add and maintain dynamically created text boxes as well as how to collect their values at the end of the wizard sequence. Feel free to grab the sample source code (requires ASP.NET 2.0). Comprehensive error checking would be in order, but I wanted to keep the sample clean to demonstrate the concepts.

    There's no need to introduce a hidden field because view state already carries all the information you need. Just pay attention to the order of events because that's the most important thing here.

    Please let me know if you have questions. Good luck!

    Milan Negovan [ASP.NET MVP]
    http://www.AspNetResources.com
    ASP.NET With Emphasis On Web Standards
  • Re: How to use dynamically generated TextBox's in a Wizard

    12-20-2006, 2:04 PM
    • Loading...
    • villelm
    • Joined on 12-20-2006, 7:02 PM
    • Posts 1

    Milan,

     Thanks for the post and sample code!  I'm working through a more complicated version of the previous posts, but am well on my way thanks to your sample.  Basically, the point I forgot is that the controls have to exist in order for ViewState to be persisted.  I knew I was missing something and originally, I didn't think I could simulate the issue, but long story short, I'm all set.

    Thanks,

    Marc

  • Re: How to use dynamically generated TextBox's in a Wizard

    06-11-2007, 7:53 AM
    • Loading...
    • Aswattha
    • Joined on 06-11-2007, 11:45 AM
    • Posts 1

     Hey Tankyou for giving code but i can not understand in that    private int? NrOfCreatedBoxes  what exactly the use of this?

    can you explain me friend.

    I will be great thakful to you 

  • Re: How to use dynamically generated TextBox's in a Wizard

    06-17-2008, 11:57 AM

    can you please give the same code in VB.net?? That would be of immense help.

     

    Thanks in advance...Smile

Page 1 of 1 (8 items)