PDA

View Full Version : creating custom ASP.NET validator controls


chump2877
09-02-2007, 05:04 AM
ASP.NET validator controls are nice, but they don;t work on all form controls, as I am finding out. Case in point, the CheckBoxList control. If you don;t believe me, try it -- you can;t assign the validation control's ControlToValidate property to a CheckBoxList control.

You could create your own validation routines for CheckBoxList controls (without using the Framework Class Library), but then you run into all kinds of problems -- most significant of which is that your custom validation doesn;t match and isn;t synchronized with ASP.NET's validation on other controls on your page.

To solve this problem, I tried implementing methods outlined in these 2 links:
1) http://authors.aspalliance.com/gzinger/columns/validation.asp?print=true&
2) http://www.4guysfromrolla.com/webtech/tips/t040302-1.shtml

By reading these articles, I figured out how to derive from the framework and create my own validation controls. On the server-side.

I got this to work on the server side, but extending ASP.NET's client-side validation is proving to be a more dauting task. I figured out that you need to locate the WebUIValidation.js file in the framework (I still can;t find the file on my development machine -- but I managed to get the code by stepping through my program in debugging mode). This JS file contains all the routines that ASP.NET validation controls use to execute client-side validation. So you could conceivably edit it to accommodate your custom control's client side validation.

The problem I am running into is that I can;t seem to figure out how to create a custom WebUIValidation.js for my web application, and have my application refer to it rather than the Framework's copy.

I read somewhere that you can edit the web.config file in your application and add the following code:


<webControls clientScriptsLocation="CustomWebUIValidation.js" />


But that doesn;t seem to be working for me. In the source code, my pages are accessing a file named WebResource.axd a lot, and I can;t locate that file either. It would seem that WebUIValidation.js and WebResource.axd refer to the same JS validation routines -- but that's just a guess.

I guess I got stuck there, when I apparently wasn;t able to point to a local, custom WebUIValidation.js in my application.

Also, I could use a better tutorial or explanation regarding how to modify the JS code so that my custom ASP.NET validation control's client side validation is in synch with the client-side behavior of other standard ASP.NET validation controls on the page.

And while I'm asking, with regard to the 2 links I posted earlier in this post, it would be nice to have a more comprehensive and in-depth tutorial/explanation regarding how to extend Framework validation controls as well (on the server side, with C#).

Thanks for any help.

ad5qa
09-04-2007, 10:27 PM
WebResource.axd is a handler or the assembly cache stuff. its a place for the system to cache informatino and stuff if I remember correctly.