当我尝试在textBox中验证输入时,它给了我这个错误:
[InvalidOperationException: WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).]
System.Web.UI.ClientScriptManager.EnsureJqueryRegistered() +2179162
System.Web.UI.WebControls.BaseValidator.RegisterUnobtrusiveScript() +10
System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +9708897
System.Web.UI.Control.PreRenderRecursiveInternal() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
我用它来检查我的验证:
<asp:RegularExpressionValidator ID="emailError"
runat="server" ControlToValidate="email"
ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ErrorMessage="Please enter a valid E-mail"></asp:RegularExpressionValidator>
当按下我的登录按钮时,我称之为:
if (emailError.IsValid == true)
{
String user = email.Text;
String pass = password.Text;
string[] lines = System.IO.File.ReadAllLines("C:\\Users\\MaxNie\\Documents\\Visual Studio 2013\\Projects\\WebApplication1\\WebApplication1\\TextFiles\\TextFile1.txt");
for (int i = 0; i < lines.Length; i++)
{
String[] line = lines[i].Split(',');
if (user.Equals(line[0]) && pass.Equals(line[1]))
{
Response.Redirect("~/Locations.aspx");
}
else { errorLabel.Visible = true; }
}
}
我错过了什么?
答案 0 :(得分:1)
禁用不显眼验证模式的方法是使用以下行:
<appSettings>
...
...
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
所以修改你的配置文件。 如果这不起作用,请点击此链接http://www.codeproject.com/Articles/465613/WebForms-UnobtrusiveValidationMode-requires-a
答案 1 :(得分:0)
我会考虑在Web.Config或Global.asax中禁用“不显眼的验证模式”。
普罗蒂普:
您可以使用if (emailError.IsValid)
代替if(emailError.IsValid == true)
答案 2 :(得分:-1)
我知道这可能不是你想要的方向,但我的建议是使用基于jQuery的验证器。这些.Net验证器比它们值得恕我直言更麻烦
像
这样的东西$("#email").on("blur", validateEmail);
function() {
if(/yourRegEx/.test(this.value)) {
$(this).next().show();
this.IsValid = false;
} else {
$(this).next().hide();
this.IsValid = true;
}
}
function formOnSubmit() { //<-- you need to wire this up
for(var i in this.getElementsByTagName("input")) {
if(! i.IsValid) e.preventDefault
}
}
<input id=email /><div style="display:none">Invalid email</div>