[thelist] ASP.NET CompareValidator Control

Chris at globet.com Chris at globet.com
Mon Oct 10 11:29:40 CDT 2005


All

I have created a CompareValidator control in ASP.NET that simply
validates the content of two text boxes. It works as I expect when
EnableClientScript is set to "false", but when set to "true" the
validation fires when either of the text fields to be validated are
given focus (or clicked on - I cannot tell which). Can anyone explain to
me what I'm doing wrong? All the examples I have found on the web have
EnableClientScript set to "false", but with no explanation why. As I
understood it, setting this attribute to "true" should give client-side
validation where available.

The code is as follows. Thanks in advance (as always) for any
assistance.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>ValidationSummary</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio
.NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript"
content="JavaScript">
		<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
		<link rel="stylesheet" href="CSS/Default.css">
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<asp:TextBox 
				id="txtValue1" 
				runat="server"></asp:TextBox>
			<asp:Label 
				id="lblEquals" 
				runat="server"> = </asp:Label>
			<asp:TextBox 
				id="txtValue2" 
				runat="server"></asp:TextBox><BR>
			<asp:CompareValidator 
				ControlToValidate="txtValue1" 
				ControlToCompare="txtValue2" 
				id="CompareValidator1"
				runat="server" 
				EnableClientScript="false" 
				Enabled="True" 
				ErrorMessage="<br>Your fields must
match.<br>" 
	
Display="Dynamic"></asp:CompareValidator>
			<BR>
			<asp:Button 
				id="btnValidateFields" 
				runat="server" 
				Text="Validate Fields"></asp:Button>
		</form>
	</body>
</HTML>

Chris Marsh
Web Developer
http://www.globet.com/
Tel: +44 20 8246 4804 Ext 828
Fax: +44 20 8246 4808

Any opinions expressed in this email are those of the individual and not
necessarily the Company. This message is intended for the use of the
individual or entity to which it is addressed and may contain
information that is confidential and privileged and exempt from
disclosure under applicable law. If the reader of this message is not
the intended recipient, you are hereby notified that any dissemination,
distribution, or copying of this communication is strictly prohibited.
If you have received this communication in error, please contact the
sender immediately and delete it from your system. 


More information about the thelist mailing list