【发布时间】:2016-12-08 09:39:38
【问题描述】:
我在一些文本框上放置了一些RequiredFieldValidators,不幸的是,一旦我这样做并尝试运行编译器,所有内容都已编译,但在我尝试测试页面时页面没有运行。相反,我收到了服务器错误:
“/”应用程序中的服务器错误。
WebForms UnobtrusiveValidationMode 需要 ScriptResourceMapping 对于'jquery'。请添加一个名为 ScriptResourceMapping jquery(区分大小写)。描述:发生未处理的异常 在当前 Web 请求执行期间。请查看 堆栈跟踪以获取有关错误及其位置的更多信息 起源于代码。
异常详细信息:System.InvalidOperationException:WebForms UnobtrusiveValidationMode 需要 ScriptResourceMapping 'jQuery'。请添加一个名为 ScriptResourceMapping jquery(区分大小写)。
来源错误:
在执行过程中产生了一个未处理的异常 当前的网络请求。有关原产地和位置的信息 可以使用下面的异常堆栈跟踪来识别异常。
堆栈跟踪:
[InvalidOperationException:WebForms UnobtrusiveValidationMode 需要 'jquery' 的 ScriptResourceMapping。请添加一个 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,布尔型 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>
【问题讨论】:
-
在 ASP.NET 论坛上查看这个问题 forums.asp.net/t/… 似乎可以解决您的问题。您知道您的目标是什么版本的 .NET?
-
不确定是哪个版本,但如果有帮助,我正在使用 Visual Studio 2010,谢谢您的链接。立即查看。
-
如果您在解决方案资源管理器中打开 web.config 文件,您应该会看到目标框架。很难判断它是 4.0 还是 4.5,但它很可能是 4.0,取决于您使用的 Visual Studio 版本以及当时与该软件捆绑的内容。基本上你需要指定如何启用内置的不显眼的 Javascript 控件。
标签: c# jquery asp.net webforms