我正在使用http://bootstrapvalidator.com/在 bootstrap asp.net 项目中使用 Visual Studio。 我遇到的问题是,我永远无法让验证按钮像示例中那样进行实际验证,当我开始在文本框中输入内容时,它可以很好地验证,但当我单击示例中的按钮时,它永远不会验证。
另一个问题是我不知道如何调用我的 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);
}
最佳答案
找到了我自己问题的答案 http://thuyvk.com/article/validate-form-su-dung-bootstrapvalidator-cho-website-aspnet-224 小心谷歌翻译,会将代码翻译成一些随机的html代码
关于javascript - 如何使用 Bootstrap Validator 提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26700318/