我在bootstrap asp.net项目中的Visual Studio中使用http://bootstrapvalidator.com/。我遇到的问题是,我永远无法像示例中那样获得验证按钮来进行实际验证,当我开始在文本框中键入内容时,它可以很好地验证,但是当我单击以下示例中的按钮时,它就无法验证。
另一个问题是,我不知道如何调用我的c#方法,该方法将在验证成功后从文本框中获取值,我可以在单击按钮时调用我的方法,但是我希望它在验证成功后立即发生。
我要寻找的是一个简单的示例,该示例如何使Submit Button验证字段,然后调用我的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对象,并且几乎不再在服务器上运行任何东西,但这对我的codebehind方法没有太大帮助
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请谨慎使用Google翻译,将代码翻译成一些随机的html代码
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句