简体   繁体   English

如何在asp.net中获取与文本框名称相同的值?

[英]how to get values of same name of text boxes in asp.net?

<script type="text/javascript">

    (function ($) {
        $(function () {

       var $formGroup = $(this).closest('.form-group');
                var $multipleFormGroup = $formGroup.closest('.multiple-form-   
       group'); 
       var $formGroupClone = $formGroup.clone();


       $(this)
                    .toggleClass('btn-default btn-add btn-danger btn-
       remove')
                    .html('–');

                $formGroupClone.find('input').val('');
                $formGroupClone.insertAfter($formGroup);

                var $lastFormGroupLast = $multipleFormGroup.find('.form-
              group:last');

                if ($multipleFormGroup.data('max') <= 
              countFormGroup($multipleFormGroup)) {
                    $lastFormGroupLast.find('.btn-add').attr('disabled', 
               true);

      }
            };



         var removeFormGroup = function (event) {
                event.preventDefault();

                var $formGroup = $(this).closest('.form-group');
                var $multipleFormGroup = $formGroup.closest('.multiple-form-
              group');

                var $lastFormGroupLast = $multipleFormGroup.find('.form-
               group:last');
                if ($multipleFormGroup.data('max') >= 
           countFormGroup($multipleFormGroup)) {
                    $lastFormGroupLast.find('.btn-add').attr('disabled', 
          false);
                }

                $formGroup.remove();
            };

            var countFormGroup = function ($form) {
                return $form.find('.form-group').length;
            };

            $(document).on('click', '.btn-add', addFormGroup);
            $(document).on('click', '.btn-remove', removeFormGroup);

        });
    })(jQuery);
</script>

This is my web page. 这是我的网页。

<body>
 <form runat ="server">
  <asp:TextBox ID="txtAddEmail" name="multipleEmail[]"  class="form-control"    
  runat="server" Width="355px" AutoPostBack="true" 
  OnTextChanged="txtFirstName_TextChanged" ></asp:TextBox>
 <span class="input-group-btn">
   <button type="button" class="btn btn-default btn-add">
    +
  </button>
  </span>

This is my code. 这是我的代码。 I try to code in onclick method but in couldn't work. 我尝试使用onclick方法编写代码,但无法正常工作。 All the values which is entered in textboxes will saved in one cell in table. 在文本框中输入的所有值将保存在表的一个单元格中。 I want to save the data row by row. 我想逐行保存数据。

can you suggest any solution for this problem? 您能为这个问题提出任何解决方案吗?

I have no idea about above java script. 我不知道上面的Java脚本。

I'm not 100% sure what you're asking but here's a simple way to save data from a TextBox. 我不是100%知道您要问的是什么,但这是一种从TextBox保存数据的简单方法。 Are you trying to save all the data inside Javascript then save it later by sending it to the server? 您是否尝试将所有数据保存在Javascript中,然后通过将其发送到服务器来保存它?

<body>
<form runat ="server">
<asp:TextBox ID="txtAddEmail" name="multipleEmail[]"  class="form-control"    
 runat="server" Width="355px" ></asp:TextBox>
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-add" onclick="SaveStuff">Add</button>
</span>

public void SaveStuff(object sender, EventArgs e)
{
    SaveToDataBase(txtAddEmail.Text);
}

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

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