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 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 application

Add App key in Web.Config File as:

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

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:



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