The selected value of my JavaScript generated drop down list is not being passed to WorkflowGen process data

Issue

The selected value of my JavaScript generated drop-down list is not being passed to WorkflowGen process data.

Background

This situation happens when you generate the items for a drop-down list using JavaScript, because it is depending on a value from another form control and you do not want any post backs or to use AJAX code.

WorkflowPage parses control values that are accessible in code-behind (server-side). If you populate your drop-down list items using JavaScript, once your page posts back you will lose all of your drop-down list items. Page ViewState keeps only values rendered at code-behind and not anything modified after the page is fully rendered.

Solution

Add a textbox that is not read only and is accessible by JavaScript. Set it to hidden using CSS style display=none (don’t use the Visible=false .NET attribute because the text box will then not render at all). Then, upon your drop-down list’s JavaScript onChange event, set the selected value to this newly-added text box. Since this textbox is an input control, your code-behind should be able to capture the input value. You can then pass this value as an OUT parameter to WorkflowGen.

Similarly, since your drop-down list does not contain any items at page render until your JavaScript code is launched, WorkflowPage cannot set the selected value of your drop down during the rendering of your web form. You need to use JavaScript to set the selected value based on the stored value in the newly-added textbox.