I've got a web app that has a few buttons that I think are better handled purely within the browser, with no asp.net codebehind blind. So one is a "Save" button that includes... onclick="if (Page_ClientValidate()) document.forms[0].submit();"

Now I wrote that, but wondered what the heck Page_ClientValidate was as I looked back. There was no other Page_ClientValidate in the project or even the entire solution. Argh. It was pretty obviously running some Microsoft validation code, and I'm currently using plain jane ASP.NET validators on this page. So I figured MS had hidden the function on me somewhere

Sure enough. Here's what I suspect is the javascript file include with the function.

   1 <script src="/WebResource.axd?d=RqZmHVG6Bo97ETCETCETC&amp;t=634245046914809245" 
2 type="text/javascript"></script>
3 <script type="text/javascript">
4 //<![CDATA[

5 function WebForm_OnSubmit() {
6 if (typeof(ValidatorOnSubmit) == "function"
7 && ValidatorOnSubmit() == false) return false;
8 return true;
9 }
10 //]]>

11 </script>


And sure enough, in that page we find the function in question.

   1 function Page_ClientValidate(validationGroup) {
2 Page_InvalidControlToBeFocused = null;
3 if (typeof(Page_Validators) == "undefined") {
4 return true;
5 }
6 var i;
7 for (i = 0; i < Page_Validators.length; i++) {
8 ValidatorValidate(Page_Validators[i], validationGroup, null);
9 }
10 ValidatorUpdateIsValid();
11 ValidationSummaryOnSubmit(validationGroup);
12 Page_BlockSubmit = !Page_IsValid;
13 return Page_IsValid;
14 }


I don't know why I don't like the setup. I mean, ASP.NET either has to throw this stuff into your page, and there's already plenty of wacky javascript in there, or slap it into an include. They chose the second, and I'm often a little upset when they do the former. Go figure. I mean, heck, they even use human-readable var names to make it easy for you to figure out what they're doing. Just like any other lib (I'm looking at you, jQuery), there's going to be stuff you didn't write, you know?

I guess I just don't like all the overhead and the way their whitespace and code includes completely break with the way I do it. When I use jQuery, there are some includes and a few lines of code in a specialized format. I can still manage the way the code feels when you run through the logic and whitespace. With this auto-generated stuff, I can't as easily. I don't know.

Anyhow, that's where Page_ClientValidate is.

Labels: