CustomValidator does not work

B

Beffmans

Hi

I have defined an customvalidator on my TextBox:

function clientvalidate(source, arguments){
{
// even number?
if (arguments.Value%2 == 0)
arguments.IsValid = true;
else
arguments.IsValid = false;
}


<asp:TextBox id="txtNumber" Runat="server" width="62px"></asp:TextBox>
<asp:CustomValidator id="custvalNumber" runat="server"
ErrorMessage="Number is not even" ControlToValidate="txtNumber"
ClientValidationFunction="clientvalidate">*</asp:CustomValidator>

what could I be doing wrong?

ch B.
 
T

Tom.PesterDELETETHISSS

function clientvalidate(source, arguments){

There are 2 { in the above code. Only one is allowed. This works for me :

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<script>
function clientvalidate(source, arguments)
{
// even number?
if (arguments.Value%2 == 0)
arguments.IsValid = true;
else
arguments.IsValid = false;
}
</script>

<asp:TextBox ID="txtNumber" runat="server" Width="62px"></asp:TextBox>
<asp:CustomValidator ID="custvalNumber" runat="server" ErrorMessage="Number
is not even"
ControlToValidate="txtNumber" ClientValidationFunction="clientvalidate"
Height="218px"
Width="300px">*</asp:CustomValidator><asp:Button
ID="Button1" runat="server" Text="Button" /></div>
</form>
</body>
</html>


Let me know it helped you or not...

Cheers,
Tom Pester
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top