javascript - 如何从使用 javascript 动态添加的文本框获取值 - c#

标签 javascript c# asp.net

我可以使用下面的代码动态添加带有文本框的表格行。

如何从添加的每个文本框中获取值,以便将其发送到我的数据库。

Jsfiddle.net/leftstick/DVEXG

var index = 1;
function insertRow(){
        var table=document.getElementById("myTable");
        var row=table.insertRow(table.rows.length);
        var cell1=row.insertCell(0);
        var t1=document.createElement("input");
            t1.id = "txtName"+index;
            cell1.appendChild(t1);
        var cell2=row.insertCell(1);
        var t2=document.createElement("input");
            t2.id = "txtAge"+index;
            cell2.appendChild(t2);
        var cell3=row.insertCell(2);
        var t3=document.createElement("input");
            t3.id = "txtGender"+index;
            cell3.appendChild(t3);
        var cell4=row.insertCell(3);
        var t4=document.createElement("input");
            t4.id = "txtOccupation"+index;
            cell4.appendChild(t4);
  index++;

}

最佳答案

使用如下代码:

var value = Request.Form["txtName1"];

关于javascript - 如何从使用 javascript 动态添加的文本框获取值 - c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45640503/

相关文章:

asp.net - 如何动态添加带有验证的控件

javascript - JSON 推送到 JavaScript 中的嵌套 JSON 对象

C# - 获取 HTTP 服务器消息

javascript - 将 MDL 与 ASP.NET Blazor 结合使用

c# - JsonConverter 等效于 HTTP GET 参数

c# - 如何解析 MVC5 中的 wwwroot 路径

javascript - 列表渲染中的动态样式

c# - 如果 Eval 不为空,如何有选择地在 GridView 中显示按钮?

javascript - 模型未填充 JSON 数据

c# - Html Agility Pack 从 div 获取特定内容