I had to do
something for work where I had to update the way an error message is being
used/displayed inside ASP.NET.
The problem
is, we cannot access the WebUIValidation.js file from ASP.NET 2.0 onwards. I
then changed my thinking to finding a way to override the current way the
validators work. In my case I had to change the way they worked, and had to add
my own javascript to the current code.
A quick way
of changing the validation, is to override ValidatorUpdateDisplay , and this is done by using good
old javascript J
I created a
separate javascript file, and copied the function from the WebResource.axd file(which is a “wrapper” for the
validation javascript inside ASP.NET), and then changed a few lines of code to
make the validator behave according to my requirements. I was able to make it
behave the same way in IE6, IE7, and Firefox.
Here is an
example of how one can override the ValidatorUpdateDisplay javascript function.
//code inside dummyJS.js
function ValidatorUpdateDisplay(val)
{
//alert("Inside
ValidatorUpdateDisplay");
if
(typeof(val.display) == "string") {
if
(val.display == "None") {
return;
}
if
(val.display == "Dynamic") {
val.style.display =
val.isvalid ? "none" : "inline";
if(val.style.display
== "inline")
{
alert("Custom
Code Here");
//Other custom
Dascode functionality here
}
return;
}
}
}