简体   繁体   English

动态(JS)表单控件:如何阅读内容?

[英]Dynamic (JS) Form Controls: How to read content?

I have an ASP.NET form where I add content () dynamicly using Javascript/jQuery: 我有一个ASP.NET表单,可在其中使用Javascript / jQuery动态添加内容():

$('#dynamicarea').append($('<input id="dyn1" type="text" value="awesome!">'));

On postback I tried to receive the content the following way: 在回发时,我尝试通过以下方式接收内容:

protected void save_OnClick(object sender, EventArgs e) {
  foreach (var key in Request.Form.AllKeys) {
    // do fancy stuff
  }
}

But Request.Form.AllKeys do not seem to have the dynamically added input fields. 但是Request.Form.AllKeys似乎没有动态添加的输入字段。

What is needed to access these fields from codebehind? 从后台代码访问这些字段需要什么?

Since you have not added the name attribute, the Request.Form.AllKeys will not contain the item. 由于尚未添加name属性,因此Request.Form.AllKeys将不包含该项。

Modify the script to include the name attribute as below. 修改脚本以包括名称属性,如下所示。

$('#dynamicarea').append($('<input id="dyn1" name="dyn1" type="text" value="awesome!">'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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