A few comments:
1. I strongly recommend using Javascript over VBScript. VBScript is
supported on IE and IE/Mac. Other browsers may generate errors when they hit
your script. The code is very easy to convert:
<script language="javascript">
function MyTest(source, arguments)
{
arguments.IsValid=false;
document.Form1.Text1.focus();
}
</script>
2. Be sure to treat everything case sensitively. You wrote "GetElementByID"
when the name is "getElementById()"
3. Be sure that functions have () after them. You wrote focus, not focus().
4. While the idea is pretty good, this custom validator will be fired when
the user edits ControlToEvaluate and on submit. If you use this technique is
several validators, when you click submit, they will all attempt to set
focus and the last one with the error will win.
5. "Professional Validation And More"
(
http://www.peterblum.com/vam/home.aspx) is a replacement to Microsoft's
validators that overcomes its numerous limitations so you can avoid custom
coding and hacks. It includes 22 validators that support more browsers than
Microsofts on the client-side.
It has several features designed to draw the user's attention to the field
with the error:
- set focus to the field with separate options for onchange events and on
submit
- change the style of the field
- change the style of the field's label or other nearby element
- show an alert
- blink the error message
--- Peter Blum
www.PeterBlum.com
Email:
PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"kpg" <ip***@thereforeiam.com> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl...
<%@ Page Language="VB" AutoEventWireup="True" %>
<HTML>
<body>
<form id="Form1" runat="server">
<h3><asp:textbox id="Text1" runat="server"></asp:textbox>
<asp:customvalidator id="CustomValidator1" runat="server"
ControlToValidate="Text1" ErrorMessage="CustomValidator"
ClientValidationFunction="MyTest"></asp:customvalidator></h3>
<p><asp:button id="Button1" runat="server" Text="Validate"></asp:button>
</form>
<script language="vbscript">
sub MyTest(source, arguments)
arguments.IsValid=false
document.Form1.Text1.focus
End Sub
</script>
</P>
</body>
</HTML>