Monday, December 2, 2013

Enable Unobtrusive Validation in ASP.NET Application

How to Enable Unobtrusive Validation in ASP.NET Application.


Prior to Unobtrusive Validation feature, a lot of JavaScript would get added into a page for each of the different validator controls.
  • Add JQuery Reference in to Application.
  • Create New ASP.net Web Application
  • Right Click Reference and click on Manage NuGet package

NuGet JQuery




  • Install JQuery Reference




There are three way to enabled Unobtrusive Validation into asp.net application






Add App key in Web.Config File as:



 <appsettings>
      <add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms">
      </add>
    </appsettings>


We can also set it at Application_Start method in Global.asax file  as



Add Referance:
using System.Web.UI;
Add Following Code in Application Start Event

 
void Application_Start(object sender, EventArgs e)
        {
            ValidationSettings.UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
        }

We can also set it at page level by setting the property of Page class as


protected void Page_Load(object sender, EventArgs e)
        {
             //Code UnobtrusiveValidationMode at Page Level
            Page.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.WebForms; 
        }


Unobtrusive Validation Benefit:


  • It can minimize the size of your overall page
  • It involves less JavaScript overall on page  


No comments:

ShareThis

Welcome

Welcome to Rajesh Prajapati, asp.net blog.
Here you can find some useful code and information about asp.net., c#, VB.net, SQL Server, Web Service, Web Designing etc