Einstellung versteckte input-Wert in Javascript, dann auf es im codebehind

Ich habe versucht, um den Wert eines hidden input per Javascript und dann den Zugriff auf den Wert von meinem C# - codebehind. Wenn ich den code ausführen, wird unten kopiert, wird der Wert, der zugewiesen wird assignedIDs ist "", die ich annehmen, ist der default-Wert für ein hidden-input. Wenn ich manuell den Wert in das html-tag, dann assignedIDs auf den Wert gesetzt.

Dieses Verhalten lässt mich vermuten, dass der Wert der Eingabe wird zurückgesetzt (neu gerendert?) zwischen dem onClientClick-und onClick-events feuern.

Ich würde schätzen jede Hilfe bei der Angelegenheit. Ich habe Stunden versucht zu lösen, was scheint wie eine sehr einfache Aufgabe.

html/javascript:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Admin Page - Manage Tasks</title>
    <script language="javascript" type="text/javascript">
        function PopulateAssignedIDHiddenInput() {
            var source = document.getElementById('assignedLinguistListBox');
            var s = "";
            var count = source.length;
            for (var i = count - 1; i >= 0; i--) {
                var item = source.options[i];
                if (s == "") { s = source.options[i].value; }
                else { s = s.concat(",",source.options[i].value); }
            }
            document.getElementById('assignedIDHiddenInput').Value = s;
            //I have confirmed that, at this point, the value of
            //the hidden input is set properly
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Panel id="EditMode" runat="server">
            <table style="border: none;">
                <tr>
                    <td>
                        <asp:Label ID="availableLinguistLabel" runat="server" Text="Available"></asp:Label><br />
                        <asp:ListBox ID="availableLinguistListBox" runat="server" Rows="10" SelectionMode="Multiple"></asp:ListBox>
                    </td>
                    <td>
                        <input type="button" name="right" value="&gt;&gt;"
                            onclick="Javascript:MoveItem('availableLinguistListBox', 'assignedLinguistListBox');" /><br /><br />
                        <input type="button" name="left" value="&lt;&lt;"
                            onclick="Javascript:MoveItem('assignedLinguistListBox', 'availableLinguistListBox');" />
                    </td>
                    <td>
                        <asp:Label ID="assignedLinguistLabel" runat="server" Text="Assigned To"></asp:Label><br />
                        <asp:ListBox ID="assignedLinguistListBox" runat="server" Rows="10" SelectionMode="Multiple"></asp:ListBox>
                    </td>
                </tr>
            </table>
            //-snip-
            <asp:Button ID="save_task_changes_button" runat="server" ToolTip="Click to save changes to task"
                Text="Save Changes" OnClick="save_task_changes_button_click" OnClientClick="Javascript:PopulateAssignedIDHiddenInput()" />
        </asp:Panel>

        <!-- Hidden Inputs -->
        <!-- Note that I have also tried setting runat="server" with no change -->
        <input id="assignedIDHiddenInput" name="assignedIDHiddenInput" type="hidden" />
    </div>
    </form>
</body>

c#

protected void save_task_changes_button_click(object sender, EventArgs e)
{
    string assignedIDs = Request.Form["assignedIDHiddenInput"];
    //Here, assignedIDs == ""; also, Request.Params["assignedIDHiddenInput"] == ""
    //-snip-
}

InformationsquelleAutor Siegesmith | 2010-04-21

Schreibe einen Kommentar