简体   繁体   English

使用必填字段验证程序会引起问题:如何解决?

[英]Using Required Field Validators causes issues: How do I resolve?

I put some RequiredFieldValidators on some textboxes, and unfortunately once I did and attempted to run the compiler, everything compiled but in my attempts to test the page the page did not run. 我在一些文本框上放置了RequiredFieldValidators,不幸的是,一旦我尝试运行编译器,所有的东西都编译了,但是在我尝试测试页面时页面却没有运行。 Instead, I received a server error: 相反,我收到服务器错误:

Server Error in '/' Application. “ /”应用程序中的服务器错误。

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. WebForms UnobtrusiveValidationMode需要针对“ jquery”的ScriptResourceMapping。 Please add a ScriptResourceMapping named jquery(case-sensitive). 请添加一个名为jquery(区分大小写)的ScriptResourceMapping。 Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code. 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。

Exception Details: System.InvalidOperationException: WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. 异常详细信息:System.InvalidOperationException:WebForms UnobtrusiveValidationMode需要对'jquery'使用ScriptResourceMapping。 Please add a ScriptResourceMapping named jquery(case-sensitive). 请添加一个名为jquery(区分大小写)的ScriptResourceMapping。

Source Error: 源错误:

An unhandled exception was generated during the execution of the current web request. 当前Web请求的执行期间生成了未处理的异常。 Information regarding the origin and location of the exception can be identified using the exception stack trace below. 可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息。

Stack Trace: 堆栈跟踪:

[InvalidOperationException: WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. [InvalidOperationException:WebForms UnobtrusiveValidationMode需要'jquery'的ScriptResourceMapping。 Please add a ScriptResourceMapping named jquery(case-sensitive).] 请添加一个名为jquery(区分大小写)的ScriptResourceMapping。
System.Web.UI.ClientScriptManager.EnsureJqueryRegistered() +2287470 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.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.Control.PreRenderRecursiveInternal() +155 System.Web.UI.Control.PreRenderRecursiveInternal()+155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974 System.Web.UI.Page.ProcessRequestMain(布尔值includeStagesBeforeAsyncPoint,布尔值includeStagesAfterAsyncPoint)+974

When I remove them, the page loads fine, and I guess I'm wanting to know what I'm missing here? 当我删除它们时,页面加载正常,我想我想知道这里缺少什么?

Code: 码:

<%@ 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" />
            &nbsp;&nbsp;
            <br />
            <br />
        </asp:Panel>
    </form>
</body>
</html>

Try adding the following to your Web.Config file: 尝试将以下内容添加到您的Web.Config文件中:

    <appSettings>
      <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    </appSettings>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM