ASP.NET 4.5 has been improved and is the latest version of ASP.NET. It includes an array of new and modified features. Today, we’ll discuss one new feature Unobtrusive Validation that is introduced with ASP.NET 4.5 .
So what is Unobtrusive Validation?
S0 now let's see a normal scenario. I have taken textbox and applied two ASP.NET validators on it. One is
RangeValidator that allows to enter the value between
1000. Let’s see the aspx code:
Now let's run the application and see the generated the HTML. Now if you look at the View Source of the page:
Now I have made the same application with Visual Studio 2011 Developer Preview. By default, Unobtrusive Validation is enabled here. So let's see the generated HTML:
So let’s see how ASP.NET 4.5 allows to configure the Unobtrusive Validation. There is one new property
UnobtrusiveValidationMode that got added, which can be assigned two values:
- None: means
UnobtrusiveValidation is set to off
- WebForms: means
UnobtrusiveValidation is enabled
This property can be configured at three places in the application. These are:
- First, it can be set at application level in config file. We need to add it in the
<add name="ValidationSettings:UnobtrusiveValidationMode" value="WebForms" />
As I discussed, it is by default enabled in ASP.NET. The above key by default added in web.config. So if you want to disable it, then change the above as:
<add name="ValidationSettings:UnobtrusiveValidationMode" value="None" />
- We can also set it at
Application_Start method in Global.asax file as:
void Application_Start(object sender, EventArgs e)
- We can also set it at page level by setting the property of
Page class as:
Page.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.WebForms;
I hope this post will help a lot to learn ASP.NET 4.5.
Software Developer (Senior)
Brij is a 3-times Microsoft MVP in ASP.NET/IIS Category and a passionate .NET developer. More than 6 years of experience in IT field, currently serving a MNC as a Tech Lead/Architect.
He is also certified as Microsoft Certified Technologies Specialist-ASP.NET and Microsoft Certified Technologies Specialist-WCF in .NET 4.0. He has also received several awards at various forums and his various articles got listed as "Article of the day" at ASP.NET Microsoft Official Website www.asp.net.
He has done MCA from NIT Durgapur and completed his graduation from Lucknow University.
Learning new technologies and sharing knowledge excites him most. Blogging, solving problems at various forums, helping people, keeps him busy entire day.
Visit his Blog: Cide wala
Area of Expertise :
C#, ASP.NET 2.0,3.5,4.0, AJAX, JQuery, JSON, XML, XSLT, ADO.Net, WCF, Active Directory, Exchange Server 2007 (EWS), Java script, Web Services ,Win services, DotnetNuke, WSS 3.0,Sharepoint Designer, SQL Server 2000/2005/2008