Fix: ASP.Net Client-side Validation

Besides managing Technically Easy, I also manage other web sites. These web sites were developed using Microsoft’s .Net framework and were coded in C#. Recently a problem had developed that caused me some grief.

In the test environment, the ASP.Net client-side validation controls (used on some web forms) worked perfectly. They highlighted the fields that weren’t filled in correctly when a visitor clicked the submit button. In production, however, they stopped working. After some serious research I determined the cause of the problem and was able to fix it. This post will explain how I did it.

ASP.Net Client-side Validation Controls

If you have developed a web site in ASP.Net chances are you have looked at, or even used the built in validation controls. These are used to validate a visitor’s input for fields on a web form. These controls use Javascript to validate the data in the client’s browser before the form is submitted back to the web server.

After the validation controls stopped working on my web forms I did some research online to fix the issue. Researching the issue returned many web pages of others that have had a similar issue. Many of the solutions that were provided were the same, and didn’t work in my situation.

Below I will recap the most common solution as well as the one that worked for me.

Reinstalling the Validation Files

The most common response to correcting the validator controls is to reinstall the needed files on the web server. This is easy to do, but requires access to the web server.

To reinstall the scripts, use the following steps:

  1. Open a DOS prompt.
  2. Navigate to the directory for the .Net framework version you are using. For example, .Net 2.0 is located in: %systemroot%\Microsoft.Net\Framework\v2.0.50727.
  3. Once you are in the framework directory, type: aspnet_regiis -c. This will reinstall the script files needed for the validation controls.
  4. Check the root of your web site to ensure that the following is created:

    Directory: [Web Root]\aspnet_client\system_web\[version of .Net]
    File: WebUIValidation.js

  5. If this file doesn’t exist, then the script install didn’t work properly. You may need to contact an administrator to look into the problem.

Once you have completed the above steps, try out the web site again to see if they are working. If they aren’t then continue to the next section.

Another Solution

The above solution may work for some, but it didn’t work for me. The file and directory existed, however, the validation still wasn’t working. I decided to look deeper into the problem.

I compared the source for the test and production site and both were identical, so the ASP files weren’t the problem.

I then cleared out my cache and reloaded the test site. I noticed that the WebUIValidation.js file was downloaded and the validation worked.

After seeing this, I cleared my Internet cache again and then requested the web form from the production server. After searching my cache, I noticed that the WebUIValidation.js file wasn’t there, meaning it wasn’t downloaded. I examined the HTML source and did notice that the file was referenced, so it should have been downloaded.

I then thought it might have been a permissions issue. I typed the URL of the WebUIValidation.js file in my browser and received a Service Unavailable message. I couldn’t retrieve the file from the server, which is why it wasn’t downloaded in the first place.

To fix this issue I did the following:

  1. I opened the Internet Information Services Manager application.
  2. I expanded the Web Sites node on the left and right-clicked the directory containing the file. I then selected Properties.
  3. Under Application settings I clicked the create button. This created a web application in that directory.
  4. I then clicked the Directory Security and then clicked the Edit button under Authentication and access control to verify the permissions.
  5. Once the permissions were good, I clicked the OK button to save.

Once I performed the above steps, I then entered the URL for the WebUIValidation.js file, and I received the text from that file. This meant I was able to download the file successfully.

I then tested the web form again to verify the validation, and everything worked again.

Notes About the Fix

The process mentioned above creates a new web application on the server. An alternative to doing the above is to simply copy the contents of the [Web Root]\aspnet_client\system_web\[version of .Net] directory to a subdirectory of you current web application. You can add/modify the following line in the web.config file of your application:

<system.web>
<webControls clientScriptsLocation=”aspnet_client/system_web/[version of .Net]/” />
</system.web>

The only problem with this method is that you would need to create a copy for each web application on your server.

Summary

I recently ran into a problem where my validation controls were working in the test environment but not in production. I tried a few fixes to get them to work but to no avail.

Digging deeper into the problem I determined it was a permission/access problem to the necessary files. I then created a web application pointing to the directory contain the validation script files and everything worked again.

Follow Me