我在一些文本框上放了一些RequiredFieldValidators,不幸的是,一旦我做了并尝试运行编译器,所有编译但在我尝试测试页面时页面没有运行。相反,我收到了服务器错误:
2>'/'应用程序中的服务器错误。WebForms UnobtrusiveValidationMode需要ScriptResourceMapping 为'jquery'。请添加一个名为的ScriptResourceMapping 的jquery(区分大小写)。描述:发生了未处理的异常 在执行当前Web请求期间。请查看 堆栈跟踪以获取有关错误及其位置的更多信息 起源于代码。
异常详细信息:System.InvalidOperationException:WebForms UnobtrusiveValidationMode需要ScriptResourceMapping 'jQuery的'。请添加一个名为的ScriptResourceMapping 的jquery(区分大小写)。
来源错误:
执行期间生成了未处理的异常 当前的网络请求。有关的来源和位置的信息 可以使用下面的异常堆栈跟踪来识别异常。
堆栈追踪:
[InvalidOperationException:WebForms UnobtrusiveValidationMode 需要ScriptResourceMapping用于'jquery'。请添加一个 ScriptResourceMapping命名为jquery(区分大小写)。]
System.Web.UI.ClientScriptManager.EnsureJqueryRegistered()+ 2287470
System.Web.UI.WebControls.BaseValidator.RegisterUnobtrusiveScript() +10 System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e)+9830941 System.Web.UI.Control.PreRenderRecursiveInternal()+83 System.Web.UI.Control.PreRenderRecursiveInternal()+155
System.Web.UI.Control.PreRenderRecursiveInternal()+155
System.Web.UI.Control.PreRenderRecursiveInternal()+155
System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 974
当我删除它们时,页面加载正常,我想我想知道我在这里缺少什么?
代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frmPersonnel.aspx.cs" Inherits="frmPersonnel" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/CIS407A_iLab_ACITLogo.jpg" PostBackUrl="~/frmMain.aspx" />
<br />
</div>
<%--Panel One: Holds the form with labels, textboxes, and buttons--%>
<asp:Panel ID="Panel1" runat="server" Height="250px" HorizontalAlign="Left" Width="500px" style="margin-left: 75px">
<%--Label 1 & Textbox 1--%>
<asp:Label ID="Label1" runat="server" Text="First Name:" width="88px"></asp:Label>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfFirstName" runat="server" ErrorMessage=" Field cannot be blank" ForeColor="Red" ControlToValidate="txtFirstName"></asp:RequiredFieldValidator>
<br />
<%--Label 2 & Textbox 2--%>
<asp:Label ID="Label2" runat="server" Text="Last Name:" width="88px"></asp:Label>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfLastName" runat="server" ErrorMessage=" Field cannot be blank" ForeColor="Red" ControlToValidate="txtLastName"></asp:RequiredFieldValidator>
<br />
<%--Label 3 & Textbox 3--%>
<asp:Label ID="Label3" runat="server" Text="Pay Rate:" width="88px"></asp:Label>
<asp:TextBox ID="txtPayRate" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfPayRate" runat="server" ErrorMessage=" Field cannot be blank" ForeColor="Red" ControlToValidate="txtPayRate"></asp:RequiredFieldValidator>
<br />
<%--Label 4 & Textbox 4--%>
<asp:Label ID="Label4" runat="server" Text="Start Date:" width="88px"></asp:Label>
<asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Format: MM/DD/YYYY" ForeColor="Red" ControlToValidate="txtStartDate" ValidationExpression="^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$"></asp:RegularExpressionValidator>
<br />
<%--Label 5 & Textbox 5--%>
<asp:Label ID="Label5" runat="server" Text="End Date:" width="88px"></asp:Label>
<asp:TextBox ID="txtEndDate" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Format: MM/DD/YYYY" ForeColor="Red" ControlToValidate="txtEndDate" ValidationExpression="^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$"></asp:RegularExpressionValidator>
<br />
<br />
<%--Buttons for Submit and Cancel--%>
<asp:Button ID="btnSubmit" runat="server" BackColor="#009900" BorderColor="#99CC00" BorderStyle="Solid" ForeColor="#CCFF66" Text="Submit" style="margin-left: 89px" />
<br />
<br />
</asp:Panel>
</form>
</body>
</html>
答案 0 :(得分:1)
尝试将以下内容添加到Web.Config文件中:
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>