Shouldn't server validation always occur when CausesValidation is true??

D

dustbort

I recently had a problem where my required field validator stopped working.
But, the page still posted back and tried to insert a record into the
database without performing server-side validation. I discovered that there
was no aspnet_client folder in the root of my IIS Web site, and when I ran
"aspnet_regiis -c", client-side validation was working again. However, what
I don't understand is why the required field validator did not validate on
the server.

I have a Button WebControl with CausesValidation = True and a
RequiredFieldValidator with EnableClientScript = True. I thought that
client-side validation provided a nice user experience and reduced
postbacks, but that server-side validation was ALWAYS performed.

Can someone explain why not having the aspnet_client folder would then cause
server-side validation to stop working???

Also, on my Windows 2000 Server SP4, the following javascript code is
emitted in the page in question (even after restoring aspnet_client):

-----------------------------------
if (typeof(clientInformation) != "undefined" &&
clientInformation.appName.indexOf("Explorer") != -1) {
if ((typeof(Page_ValidationVer) != "undefined") && (Page_ValidationVer
== "125"))
ValidatorOnLoad();
}
-----------------------------------

But on my windows XP Pro SP2 development machine, the following code is
emitted in this page:

-----------------------------------
if (typeof(clientInformation) != "undefined" &&
clientInformation.appName.indexOf("Explorer") != -1) {
if (typeof(Page_ValidationVer) == "undefined")
alert("Unable to find script library
'/aspnet_client/system_web/1_1_4322/WebUIValidation.js'. Try placing this
file manually, or reinstall by running 'aspnet_regiis -c'.");
else if (Page_ValidationVer != "125")
alert("This page uses an incorrect version of WebUIValidation.js.
The page expects version 125. The script library is " + Page_ValidationVer +
".");
else
ValidatorOnLoad();
}
-----------------------------------

If the Win2k server had emitted the checks and alert() lines, I would have
been able to find the cause of the problem much quicker. Does anyone know
what accounts for the difference and what I can do to get my server to emit
the second code fragment???
 
B

Bruce Barker

for serverside validation to run, your backend code must call it, say thru
accessing the IsValid property which in turn will fire the validation
routines.

-- bruce (sqlwork.com)
 
D

dustbort

No, I don't think so. From the .NET Framework Class Library under
Button.CausesValidation Property:

"By default [CausesValidation = True], page validation is performed when a
Button control is clicked. Page validation determines whether the input
controls associated with a validation control on the page all pass the
validation rules specified by the validation control."

This means that page validation is automatically performed when when
CausesValidation = True.
My understanding is that you only have to explicitly call Validate() and
check IsValid if you have set CausesValidation = False because you want to
do selective validation. In my case, CausesValidation = True . So why
didn't the page validate on the server?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top