Note that there are some explanatory texts on larger screens.

plurals
  1. POWorking With ViewState with JavaScript Altered Control
    primarykey
    data
    text
    <p>Hi I'm trying to utilize more java-script, jquery, ajax in my asp code. So for a project I built this field chooser using java-script. <img src="https://i.stack.imgur.com/UcFHv.png" alt="enter image description here"> </p> <pre><code> &lt;asp:ListBox ID="lb1" runat="server" Height="400px" Width="170px"&gt;&lt;/asp:ListBox&gt; &lt;input type="button" id="_b_Add" value="Add &gt;" onclick="add();" style="padding:5px; margin-left:5px; margin-top:15px; width: 131px;" /&gt; &lt;input type="button" id="_b_Rem" value="&lt; Remove" onclick="remove();" style="padding:5px; margin-top: -25px; margin-left:5px; width: 131px;" /&gt; &lt;input type="button" value="Up" onclick="moveUp(document.getElementById('lb2'));" style="padding:5px; margin-left:5px; width: 131px;" /&gt; &lt;input type="button" value="Down" onclick="moveDown();" style="padding:5px; margin-left:5px; margin-top: -25px; width: 131px;" /&gt; &lt;asp:Button ID="_b_Reset" runat="server" Text="Reset" Width="131px" style="padding:5px; margin-left:5px; margin-top:40px;" onclick="_b_Reset_Click" /&gt; &lt;asp:Button ID="_b_Run" runat="server" Text="Run" Width="131px" style="padding:5px; margin-left:5px; margin-top:10px;" onclick="_b_Run_Click" /&gt; &lt;asp:ListBox ID="lb2" runat="server" Height="400px" Width="170px" AppendDataBoundItems="True" Enabled="False"&gt;&lt;/asp:ListBox&gt; </code></pre> <p>and here is the important javascript:</p> <pre><code> function prom() { { $.prompt('Maximum Number of Custom Types is 14 '); } } function add() { var opt = document.createElement("option"); var sel = document.getElementById("lb1").selectedIndex; if ((document.getElementById("lb1").selectedIndex) != -1 &amp;&amp; document.getElementById("lb2").length &lt; 14) { document.getElementById("lb2").options.add(opt); opt.text = (document.getElementById("lb1").options[document.getElementById("lb1").selectedIndex].text); opt.value = (document.getElementById("lb1").value); document.getElementById("lb1").options.remove((document.getElementById("lb1").selectedIndex)); document.getElementById("lb1").options.SelectedIndex = sel; } else { prom(); } } function remove() { var opt = document.createElement("option"); var sel = document.getElementById("lb2").selectedIndex; if ((document.getElementById("lb2").selectedIndex) != -1) { document.getElementById("lb1").options.add(opt); opt.text = (document.getElementById("lb2").options[document.getElementById("lb2").selectedIndex].text); opt.value = (document.getElementById("lb2").value); } document.getElementById("lb2").options.remove((document.getElementById("lb2").selectedIndex)); document.getElementById("lb2").options.selectedIndex = sel; } </code></pre> <p>EDIT *** </p> <p>Testing the values in lb2 </p> <pre><code> foreach (var item in lb2.Items.Cast&lt;ListItem&gt;()) { TextBox1.Text += (item.Value).ToString(); i++; } </code></pre> <p>This works fine on the lb1 not but when the item have been added client side its no good.</p> <p>Basically now on run the values of lb2 should be iterated and fed into my report class. However I quickly realized that the changes made by the java script to lb2 are not reflected in the viewstate when the "_b_Run_Click" event is fired. So after digging around a bit I seem to get the impression that the solution is to use a hidden field ... My question is (being a js noob) how exactly do you do that and is there an more elegant alternative ? </p> <p>Thanks </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload