I have a website form (c#) that sits inside a multiview control. The muliview control has 4 steps, so the first 3 steps gather information and if valid move to the next view on button click.
I want to dynamically build the form based on previous answers, but from what I’ve read so far I’m a little unsure how to make this happen.
For example, on step 1, a user completes some textbox controls and clicks submit.
Based on the data submitted in panel 1, the next panel needs to create a number of controls dynamically – some labels, some textboxes.
As this click is after both the init and page_load, I’m unsure how this will work.
Of course I could create all the label/textbox controls up front and disable them as necessary, but this seems to be quite a poor use of resource.
Bottom line, I’m inexperienced at working with dynamic controls so any advice would be appreciated.
Ok, below i’ve pasted working example.
Things to be aware of:
Message=Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.Source=System.Web
ErrorCode=-2147467259
set this property on your dynamic controls
EnableViewState = falseData for this example looks like this
Brand Engine Color Cost
VW, 1.2, Black, 72 000
VW, 1.2, White, 70 000
VW, 1.6 TDI, Red, 79 500
VW, 1.6 TDI, White, 78 800
Ford, 1.6, Black, 57 600
Ford, 1.6, Green, 57 100
Ford, 2.0 TDCi, Black, 87 300
Ford, 2.0 TDCi, White, 86 600
Basicaly this works like this:
Ofcourse you can also do logic with drop downs etc.
Page code:
Code behind:
If you have any additional questions I will be glad to help