简体   繁体   中英

ASP.NET data generated by javascript not received

here is part of my ASPX file

<td>
                    <p>Function</p>
                    <asp:ListBox ID="Functions" runat="server"></asp:ListBox>
                    <asp:DropDownList ID="FunctionDropDown" runat="server"></asp:DropDownList>
                    <input type="button" value="Assign function" onclick="AssingFunction();" />
                </td>

and here is javascript function triggered on button click

function AssingFunction() {
var content = '"<option value="' + $("#MainContent_FunctionDropDown").find(":selected").text() + '">' + $("#MainContent_FunctionDropDown").find(":selected").text() + '</option>';
$("#MainContent_Functions").append(content);

}

so this part of code is on client side adding options from dropdown menu to ListBox control, that works pretty fine.

My problem is that if I want extract data (added options) from LisBox in code behind, there are no data (items) in ListBox (Functions). So I assume that data added on client side are not posted back to server. Is there any chance to fill ListBox on client side and send those data to server for further operations?

Dropdown menu is filled on page load in code behind.

asp:ListBox is a server-side control, it renders as a select element on client, but this doesn't mean if you add more option elements on the client they will automatically translate into new asp:ListItem elements on the server.

You may have to rethink the way new data is submitted from client to server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM