So I have a page where I would like to be able to add multiple, dynamic users to a record in a database. Here’s the rough start page:
<div id="records">
<div id="userRecord">
Name: <asp:TextBox runat="server" ID="objNameTextBox"></asp:TextBox> <br />
Phone Number: <asp:TextBox runat="server" ID="objPhoneNumberTextBox"></asp:TextBox> <br />
</div>
</div>
And the jquery:
$(function () {
$(".button").button().click(function (event) { addnew(); event.preventDefault(); });
})
function addnew() {
$('#userRecord').clone().appendTo('#records');
}
So my question is what do I use within ASP.NET to be able to poll all of the data in the form and add a unique record for each #userRecord div within the #records div? Yes – I should change the userRecord to a class – I will deal with that. This is just simple testing here.
Should I look in JSON for this type of function? I’m not familiar with it but could figure it out if that is indeed my best option. Thanks for the guidance!
You cannot duplicate ASP.NET web forms controls with Javascript, because the runtime keeps tracks of the controls in your HTML, if you try to duplicate them with Javascript, you duplicate the HTML and they may look the same, but ASP.NET won’t know anything about them.
You could do it using an UpdatePanel, and triggering a post back in it with your button and create the controls in your backend programmatically and appending them to said panel, that would mimic what you are trying to do.
Another way would be creating HTML inputs and submitting the things to a web service, or a web method and do the actual insertions to the database there, but normal ASP.NET methods won’t work on said inputs, as they are not controls as far as ASP.NET is concerned.