1

我使用http://bootstrapvalidator.com/与bootstrap asp.net项目中的visual studio。 问题我有,我永远不会验证按钮来实际验证,就像它在例子中所做的那样,当我开始在文本框中输入内容时验证正确,但是当我点击按钮时,从未验证下面的示例。如何使用Bootstrap Validator提交表单

另一个问题是我不知道如何调用我的c#方法,它将在验证成功后从文本框中获取值,我可以在按钮单击时调用我的方法,但是我希望它在验证成功后立即发生。

我在找的是一个简单的例子,如何使提交按钮验证字段,然后调用我的C#方法,它将从输入中读取值。

我在网上找不到一个单一的例子,而且我对JavaScript也不太了解。

下面是一些测试代码,我有

<div class="form-group" id="nameEmail2"> 
     <div class="form-group"> 
      <label for="inputContactName" class="col-sm-5 control-label">Contact Name </label> 
      <div class="col-sm-7"> 
       <input type="text" class="form-control" name="fullName1" id="TextBox1" placeholder="Contact Name" maxlength="50"/> 
      </div> 
     </div> 
     <div class="form-group"> 
      <label for="inputContactEmail" class="col-sm-5 control-label">Contact Email <b>*</b></label> 
      <div class="col-sm-7"> 
       <input type="text" class="form-control" name="email1" id="TextBox2" placeholder="Contact Email" maxlength="50"/> 
      </div> 
     </div> 
     <div class="form-group"> 
      <div class="col-sm-5 col-sm-offset-3"> 
       <button type="submit" runat="server" onserverclick="submitValidate" class="btn btn-default">Validate</button> 
      </div> 
     </div> 
     </div> 



     <script type="text/javascript"> 
      $(function() { 
       $('#nameEmail2').bootstrapValidator({ 
        feedbackIcons: { 
         valid: 'glyphicon glyphicon-ok', 
         invalid: 'glyphicon glyphicon-remove', 
         validating: 'glyphicon glyphicon-refresh' 
        },       
        fields: { 
         fullName1: { 
          validators: { 
           notEmpty: { 
            // enabled is true, by default 
            message: 'The full name is required and cannot be empty' 
           }, 
           stringLength: { 
            enabled: true, 
            min: 8, 
            max: 40, 
            message: 'The full name must be more than 8 and less than 40 characters long' 
           }, 
           regexp: { 
            enabled: false, 
            regexp: /^[a-zA-Z\s]+$/, 
            message: 'The full name can only consist of alphabetical, number, and space' 
           } 
          } 
         }, 
         email1: { 
          validators: { 
           emailAddress: { 
            message: 'The value is not a valid email address' 
           } 
          } 
         } 
        } 
       }); 
      }); 
     </script> 

我已删除大多数ASP对象,并且几乎没有在服务器上的任何更多的运行,但没有帮助很大,这里是我的代码隐藏方法

protected void submitValidate(object sender, EventArgs e) 
{ 
    string contactName = Request.Form["fullName1"]; 
    string email = Request.Form["email1"]; 
    System.Diagnostics.Debug.Write("test",email); 
} 

回答