C# 如何验证asp.net中从SQL填充的下拉列表(UnobtrusiveValidationMode)错误
我有一个从SQL数据库填充的下拉菜单,默认值是:selectdeveloper。我有一个表单向导,向导的第二步是选择开发者。 我想验证这个下拉菜单;如果用户使用默认值Select Developer保持原样,则会出现错误消息。 我得到了这个错误: WebForms UnobtrusiveValidationMode需要ScriptResourceMapping 对于“jquery”。请添加名为的ScriptResourceMapping jquerycase敏感 以下是我的代码: .aspx: web.debug.config和web.config: 编辑1: @山本哲也 1-首先,我在web.config中添加 2-其次,我创建文件->新建->文件->全局应用程序类global.asax,并将代码放入应用程序\u Start中 3-然后我输入.aspxC# 如何验证asp.net中从SQL填充的下拉列表(UnobtrusiveValidationMode)错误,c#,jquery,asp.net,C#,Jquery,Asp.net,我有一个从SQL数据库填充的下拉菜单,默认值是:selectdeveloper。我有一个表单向导,向导的第二步是选择开发者。 我想验证这个下拉菜单;如果用户使用默认值Select Developer保持原样,则会出现错误消息。 我得到了这个错误: WebForms UnobtrusiveValidationMode需要ScriptResourceMapping 对于“jquery”。请添加名为的ScriptResourceMapping jquerycase敏感 以下是我的代码: .aspx:
<form .....>
<asp:ScriptManager runat="server" EnableScriptGlobalization="True" EnableCdn="True">
<Scripts>
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" />
</Scripts>
</asp:ScriptManager>
<asp:DropDownList ID="developers_DropDownList" name="developers_DropDownList" class="form-control col-md-7 col-xs-12" runat="server"></asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredValidator1" runat="server"
ErrorMessage="Please select a value!"
ControlToValidate="developers_DropDownList"
InitialValue="Select Developer"></asp:RequiredFieldValidator>
我得到了这个错误:
“jquery”不是有效的脚本名称。名称必须以“.js”结尾
在global.asax中,我得到:
ScriptResourceDefension不包含的Defension
LoadSuccessExpression
编辑2:
在实现了所有@Tetsuya Yamamoto notes之后,我没有收到任何错误,但是当我离开下拉列表选择Developer时,仍然没有出现任何验证错误 首先,确保这些行在web.config中已经可用,而不仅仅是web.debug.config: 下一件重要的事情是,在asp:ScriptReference元素中引用jQuery之后放置WebUIValidation.js,如下所示:
<asp:ScriptManager runat="server" EnableScriptGlobalization="True" EnableCdn="True">
<Scripts>
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" />
</Scripts>
</asp:ScriptManager>
ValidationSettings备注:在以下位置设置UnobtrusiveValidationMode:
如果此键值设置为无[默认],则ASP.NET应用程序
将在页面中内联使用4.5之前的JavaScript行为
客户端验证逻辑。如果此键值设置为WebForms,
ASP.NET使用HTML5数据属性和来自
添加了客户端验证逻辑的脚本参考
更新说明:
有关UnobtrusiveValidationMode和LoadSuccessExpression方法用法的错误仅在将project的targetFramework设置为.NET 4.5或更高版本时出现,而在将targetFramework设置为早期版本4.0时可能不存在。如果要在版本4.0模式下运行项目,请尝试跳过以上所有步骤(安装软件包除外),改用此配置:
<system.web>
<compilation debug="false" targetFramework="4.0" />
<httpRuntime targetFramework="4.0" />
</system.web>
参考:
类似问题:
首先,确保这些行在web.config中已经可用,而不仅仅是web.debug.config: 下一件重要的事情是,在asp:ScriptReference元素中引用jQuery之后放置WebUIValidation.js,如下所示:
<asp:ScriptManager runat="server" EnableScriptGlobalization="True" EnableCdn="True">
<Scripts>
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" />
</Scripts>
</asp:ScriptManager>
ValidationSettings备注:在以下位置设置UnobtrusiveValidationMode:
如果此键值设置为无[默认],则ASP.NET应用程序
将在页面中内联使用4.5之前的JavaScript行为
客户端验证逻辑。如果此键值设置为WebForms,
ASP.NET使用HTML5数据属性和来自
添加了客户端验证逻辑的脚本参考
更新说明:
有关UnobtrusiveValidationMode和LoadSuccessExpression方法用法的错误仅在将project的targetFramework设置为.NET 4.5或更高版本时出现,而在将targetFramework设置为早期版本4.0时可能不存在。如果要在版本4.0模式下运行项目,请尝试跳过以上所有步骤(安装软件包除外),改用此配置:
<system.web>
<compilation debug="false" targetFramework="4.0" />
<httpRuntime targetFramework="4.0" />
</system.web>
参考:
类似问题:
检查此项检查此项请检查我在web.debug.config和web.config部分的帖子编辑以查看是否有错误请检查我在web.debug.config和web.config部分的帖子编辑以查看是否有错误
protected void Application_Start(object sender, EventArgs e)
{
string jqversion = "1.12.4"; // match this to available jQuery version you have
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
{
Path = "~/Scripts/jquery-" + jqversion + ".min.js",
DebugPath = "~/Scripts/jquery-" + jqversion + ".js",
CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + jqversion + ".min.js",
CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + jqversion + ".js",
CdnSupportsSecureConnection = true,
LoadSuccessExpression = "window.jQuery"
});
}
<asp:ScriptManager runat="server" EnableScriptGlobalization="True" EnableCdn="True">
<Scripts>
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" />
</Scripts>
</asp:ScriptManager>
Install-Package AspNet.ScriptManager.jQuery
Install-Package AspNet.ScriptManager.jQuery.UI.Combined
<system.web>
<compilation debug="false" targetFramework="4.0" />
<httpRuntime targetFramework="4.0" />
</system.web>