ASP.NET: adding controls client-side

前端 未结 6 810
我在风中等你
我在风中等你 2020-12-18 05:25

If I have a page with a form (imagine a simple one with just TextBoxes and a submit button) and I want to allow the user to dynamiccally add more TextBoxes to the form via j

6条回答
  •  庸人自扰
    2020-12-18 05:58

    On client side, make a JS function for creating the inputs, for example:

    var numCtrl = 1; // depends on how many you have rendered on server side
    var addCtrl = function() {
        var in = document.createElement('input');
        in.name = "control" + ++i;
        in.type = "text";
        in.id = "control" + i;
        document.getElementById("yourcontainer").appendChild(in);
    }
    

    ..on the server side just lookup your HTTP params collection, iterate through it, and select only those matching /control\d*/

提交回复
热议问题