码迷,mamicode.com
首页 > Web开发 > 详细

Visual Studio 2013新建ASP.NET项目使用Empty模板,在页面中使用验证控件出错的解决方案

时间:2015-02-12 15:43:07      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

Visual Studio 2013新建ASP.NET项目使用Empty模板,在页面中使用验证控件,运行页面,会出现如下的错误:

技术分享

错误原因

         VisualStudio 2012(或2013) WebForm 4.5 开发中,很多控件默认Enable了 Unobtrusive ValidationMode(所谓Unobtrusive Validation,就是一种隐式的验证方式)的属性(和jquery的引用相关),但并未对其进行赋值, Programmer必须手动对其进行设置。比如,在进行数据验证时使用的各种validator(今天使用的RequiredFieldValidator控件),以及进行authorization及authenication设置时,由于需要在前端调用jquery来进行身份验证,都默认Enable了 Unobtrusive ValidationMode。如果不对该属性进行配置,将会产生ERROR。

 

         解决方法

 

         从错误产生的原因我们能很容易的对症下药,从错误原因中我们得到的解决问题的方法无非有三:

         1、  在程序允许的情况下,降低.Framework的版本,具体方法如下:

  1. <!--修改前-->  
  2. <system.web>  
  3.     <compilation debug="true" targetFramework="4.5" />  
  4. <httpRuntime targetFramework="4.5" />     <!—将其删除-->  
  5. </system.web>  
  6.   
  7. <!--修改后-->  
  8. <system.web>  
  9.     <compilation debug="true" targetFramework="4.0" />  
  10. </system.web>  


         2、更改Web.config配置文件设置Unobtrusive ValidationMode的类型,具体方法如下:

  1. <!--修改前-->  
  2. <system.web>  
  3.     <compilation debug="true" targetFramework="4.5" />  
  4. <httpRuntime targetFramework="4.5" />  
  5. </system.web>  
  6.   
  7. <!--修改后-->  
  8. <system.web>  
  9.     <compilation debug="true" targetFramework="4.5" />  
  10. <httpRuntime targetFramework="4.5" />  
  11. </system.web>  
  12.   
  13. <appSettings>  
  14.         <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />  
  15. </appSettings>  

 

          3、找到相应的AspNet.ScriptManager.jQuery.dll文件将其复制到bin文件夹下。

         由于我是新建的空Web应用程序,因此没有添加Jquery。我们可以通过新建一个非空的Web应用程序将里面的对应的Jquery文件粘贴到上文提到的文件夹下。

为了方便,大家可以点击下载AspNet.ScriptManager.jQuery.dll。

        本文参考了:http://blog.csdn.net/senior_lee/article/details/35337081?utm_source=tuicool

Visual Studio 2013新建ASP.NET项目使用Empty模板,在页面中使用验证控件出错的解决方案

标签:

原文地址:http://www.cnblogs.com/zhouhb/p/4288183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!