Sai Stuff to Developers

December 4, 2012

Unobtrusive Validation in Framework 4.5 Data Validations

Filed under: DotNet — tosaik @ 7:41 am
Tags: , , , , ,

Today I was working on ASP.NET web application on framework 4.5; I came across a strange error which I never experienced in my past working on earlier environments of dot net framework and that is error titled

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for ‘jquery’. Please add a ScriptResourceMapping named jquery(case-sensitive).

When I dig in to this issue and found the root cause of this issue and here my case study about this issue…

Unobtrusive Validation is a new concept in Framework 4.5, and this is by default enables when we create a new ASP.NET web application by adding one of the key in a Web.Config->appsettings section as below

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

What exactly this validation does for us

Forms with complex data including validators tend to generate too much JavaScript code in the page, which can represent about 60% of the code. With unobtrusive validation enabled, your HTML code will look cleaner and tidier.

For example we will compare the HTML code generated by both configurations.


Steps to create the sample application without unobtrusive validation enabled (default for all earlier versions)

1)      Open Visual studio 2012 IDE and create a new Web Application as shown below










2)      Now Press F5 to start the web application.

3)      Right-click on the browser page, and select View Source option to open the HTML code generated by the application.

4)      Scroll through the page source code and notice that ASP.NET has injected JavaScript code in the page to perform the validations and show the error list.


5)      Select the Script tab and expand the “{your current page}.aspx” combo to see all the referenced scripts. Notice that there are no references to the jQuery library. The validations are performed using the Microsoft Ajax Libraries together with JavaScript code injected within the page.


Steps to create the sample application with unobtrusive validation enabled (default for all new version(s))

1)      Now you will enable unobtrusive validation. Open Web.Config and locate ValidationSettings:UnobtrusiveValidationMode key in the AppSettings section. Set the key value to WebForms.

    <add key="aspnet:uselegacysynchronizationcontext" value="false" />
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms"/>

2) Open the Global.asax.cs file and add the following using statement

using System.Web.SessionState;
using WebFormsLab.Model;
using System.Web.ModelBinding;

3)      Within the Application_Start method of the Global.asax.cs file, add the following code

ScriptResourceDefinition myScriptResDef = new ScriptResourceDefinition();
myScriptResDef.Path = "~/Assets/Scripts/jquery-1.7.1.min.js";
myScriptResDef.DebugPath = "~/Assets/Scripts/jquery-1.7.1.js";
myScriptResDef.CdnPath = "";
myScriptResDef.CdnDebugPath = "";
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", null, myScriptResDef);

4)      Open Site.Master. Add the code below to include a ScriptManager on the page to include a script reference to the jQuery client library.

<form runat="server">
<asp:ScriptManager ID="uxScriptManagerMasterPage" runat="server" EnableCdn="False">
    <asp:ScriptReference Name="jquery" />

5)      Now Press F5 to start the web application.

6)      Right-click on the browser page, and select View Source option to open the HTML code generated by the application. Notice that by enabling the unobtrusive validation ASP.NET has replaced the injected JavaScript code with data- *attributes.


Don’t want this feature enabled?

Simply add the following setting in your AppSettings section in your web.config if it doesn’t exist. If already exist make value as “none” as shown below

 <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />


With Unobtrusive validation we reduce the unnecessary JavaScript code generation for all validation controls by runtime. As if we enable this validation the runtime by default get and use the jquery environment to perform these validations through this we can have least overhead of unwanted JavaScript code in our HTML page and it also effect the improvement in the performance and take less time in rendering and loading your pages.

I Hope you got advantage of this article…

Please drop a comment if you like it…

Thanks Happy Coding  🙂


November 30, 2012

Error: the exec task needs a command to execute in visual studio

Filed under: DotNet — tosaik @ 6:02 am
Tags: , ,

Got Error:

the exec task needs a command to execute in visual studio


This is a common issue in visual studio and this error could be a cause when we add/remove the Pre-build event command line(s) and in Post-build event command line(s)…

Generally visual studio gives every line as a new command line to the command prompt to execute with “EXEC” command, if we by mistake keep any empty line… visual studio also send this empty line as a new command line and command prompt throws an error as it expects a valid command but what we sent is not a valid command to it…

as you can see the below image as i selected the empty line which by mistakenly entered in the project->properties Build Events Tab section…


Hope this solution work for you….

Happy Coding 🙂

October 22, 2012

Download: Visual Studio Express 2012

Filed under: DotNet — tosaik @ 11:02 am
Tags: , , , ,

Visual Studio Express 2012(Free)

Microsoft Visual Studio Express 2012 for Web is a free and robust development environment for building, testing, and deploying web applications across the Microsoft Web Platform. After installation, you can try this product for up to 30 days. You must register to obtain a free product key for ongoing use after 30 days.

Download Here

Visual Studio 2012 Express for Windows Desktop(Free)

You can use Visual Studio Express 2012 for Windows Desktop to build powerful desktop apps in C#, Visual Basic, and C++. You can target client technologies such as Windows Presentation Foundation (WPF), Windows Forms, and Win32. After installation, you can try this product for up to 30 days. You must register to obtain a free product key for ongoing use after 30 days.

Download Here

Happy Coding 🙂

June 4, 2012

Quick tour of Visual Studio 2012

Filed under: DotNet — tosaik @ 12:43 pm
Tags: ,




A quick tour of the new features in Visual studio 2012.

Code window resize

A feature you can turn on/off is automatic resizing of the code window. When you are editing your code, selecting the code window maximizes it at the expense of Solution Explorer, the Output pane, etc.

Edit code while it executes

You could do it with Visual Basic 6 back in the ’90s and finally you can do it in VS2012. While the code is executing, you can pause it (breakpoint / debugging) and modify the code. Just as it did back in the ’90s, the compiler will carry on working with the code you just wrote.

Google It!

They just made everyone’s life easier by providing a button called Google It! In case of any run time error message box.

Automatically add semicolons.

Rumor has it that the compiler will also automatically add closing brackets and braces.

Advanced copy and pasting of code

The art of developing good software includes the skill of copying and pasting code found on the Internet. To make your life easier, VS2012 will apply some sense to the pasted code and rewire it for you. Simply write your stub method…Ask a question at or maybe try Goggling the code you need. Once you have it, simply copy the code and paste it into your stub method…then the magic begins. The compiler has recognized and wired up your connection string, replaced “textBox1.Text” with “term”, and because you are returning a string from this method, it assumes that you want the first result from the table and so will suggest returning that for you.

Evil Code Monkey ™

After copying and pasting code, things can get pretty messy really quickly. IntelliSense now includes Evil Code Monkey™ which will point out your ugly code, shaming you into Goggling the correct way to write it.

Language Style

VB, C# or F# – it’s all just language styles!

When you are viewing code you can opt to have it translated from its original source into VB, C# or into some of the new styles.

Add Reference dialog

Finally they figured out what people meant when they asked for a proper “Add Reference” dialog. They now provide the ultimate mix of speed and flexibility.

The creation of high quality applications is also something which Microsoft is aiming for with the release of VS2012, with the inclusion of high quality testing and debugging tools that allow local debugging, as well as the ability to debug apps on the simulator and remotely on a connected device. Microsoft has undergone a lengthy process in an attempt to ensure that Visual Studio 2012 allows continuous value and quality to be delivered through the use of the software. With the inclusion of what they called Application Lifecycle Management, development teams of any size can be confident that required collaboration to deliver apps will be seamless and problem free.

The Visual Studio 2012 RC is available to download from the official VS product website and includes a lot of final touches and enhancements that makes it substantially different from the previously released beta versions of the product.

Visual Studio 2012 is available to download from the Visual Studio product website, with users being able to get their hands on the Ultimate, Premium and Professional versions along with Microsoft’s .NET Framework 4.5 RC required for the install. As always with pre-released builds, treat this installation accordingly and make sure to read the supplied read me files attached with the downloads.

May 2, 2012

Finding what are the Assemblies are loaded currently in Current AppDomain

Filed under: Uncategorized — tosaik @ 7:38 am
Tags: ,

Today i am going to show you a problem solving issue, generally we use to create an separate assemblies (i.e, dll’s) and reference them to the main application in this process most common issue is we have coded a logic in our dll but its not applied/running through main application… as many people ask me how to fix this issue due to this reason i may posting this… the issue is simple and cause of issue may be of two reasons those are:

  1. Your dll may not updated in you main application.
  2. You may coded in one location and referring from other location in your main Application.

These two are most common issues, the first will be raised if you are manually copy the dll from the bin folder of you

component project to your main application bin folder. If you do like this every time you change your component you need to repeat this process, if you forgot to update the above issue will occur.. for this a better option is to while adding reference to you component select the component project instead of selecting a dll in your bin folder this will
automatically updates your component dll in your main application’s bin folder whenever a change is done this way we can fix the 1st cause of issue.


Second cause is straight forward and most people suffers with this kind of issue, to fix this issue we need to know from where the respective component is picking by the CLR.. we can do this using Modules window in visual studio 2010.
To open this window go to Debug->Windows->Modules as shown below.
Note: This will be visible while running the application.


Now you will see the below window with grid of Assemblies loaded


In this window you can find all the information regarding your component from where it is loaded and etc.., using this we can fix another issue too as many people cannot debug their components in the main application the reason for this is your main application doesn’t have the respective components symbol file i.e.., .pdb file and in this modules window you can find is the CLR picks its symbol file or not.. if not just copy the latest one in to your main application’s bin folder and build and restart the application.

That’s it …… Have an Happy Coding  🙂


December 16, 2011

With Visual Studio 2010, How To Add a Second Project To a Solution

Filed under: DotNet — tosaik @ 11:01 am

Say you are creating new Windows Application Project using Visual Studio 2010, the project created successfully but I am unable to see the solution created in the solution explorer window due to this I am unable to add another project to the existing solution. 








Finally I got the Solution and fix the issue, please follow the steps to fix this issue…

Step1: Open Visual Studio 2010, and select Menu Tools -> Options 










Step 2: Now go to Projects and Solutions -> General section in the tree view on left side of options window and check the checkbox “Always show solution” as shown below








That’s it now again try to create the project you will be shown by the solution so that you can add as many projects you can….








Happy Coding… 🙂

Blog at

%d bloggers like this: