473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I use client-side validation with a custom validator?

Hello,

I have a custom validator on my page, and have the server-side code
working fine. I want to add a client-side funtion as well, but am not
sure how to wire it in so that it works with the other validators on the
page.

I specified the name of the Javascript function with the
ClientValidationFunction attribute of the custom validator, and it is
being called fine. However, if the validator returns false (ie bad
data), nothing happens on the client. With the other validators, I get a
message box popping up with the warnings, and I get the red text by the
control so the user can see which control fired the error.

How do I get the custom validator to do this? Here is the server tag...

<asp:CustomValidator ControlToValidate="txtDeliveryCountries"
OnServerValidate="ValidateTxtDeliveryCountries"
ClientValidationFunction="ValidateTxtDeliveryCount riesJS"
Display="Dynamic" Text="At least one country name does not start with
U_, E_ or W_" Runat="Server" />

(the point of the validator is that it checks a multiline textbox, that
is supposed to contain a list of countries, each of which has one of U_,
E_ or W_ as a prefix. The validator checks to make sure they didn't
enter a country without a prefix, or one with an invalid prefix).

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
2 1766
Hi Alan,

You wrote: "if the validator returns false". The definition of the
client-side validation function requires that you set the args parameter's
IsValid property to true or false:

function ValidateTxtDeliveryCountriesJS(source, args)
{
if (valid)
args.IsValid = true;
else
args.IsValid = false;
}

Note that names like args and IsValid are case sensitive.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:bO**************@nospamthankyou.spam...
Hello,

I have a custom validator on my page, and have the server-side code
working fine. I want to add a client-side funtion as well, but am not sure
how to wire it in so that it works with the other validators on the page.

I specified the name of the Javascript function with the
ClientValidationFunction attribute of the custom validator, and it is
being called fine. However, if the validator returns false (ie bad data),
nothing happens on the client. With the other validators, I get a message
box popping up with the warnings, and I get the red text by the control so
the user can see which control fired the error.

How do I get the custom validator to do this? Here is the server tag...

<asp:CustomValidator ControlToValidate="txtDeliveryCountries"
OnServerValidate="ValidateTxtDeliveryCountries"
ClientValidationFunction="ValidateTxtDeliveryCount riesJS"
Display="Dynamic" Text="At least one country name does not start with U_,
E_ or W_" Runat="Server" />

(the point of the validator is that it checks a multiline textbox, that is
supposed to contain a list of countries, each of which has one of U_, E_
or W_ as a prefix. The validator checks to make sure they didn't enter a
country without a prefix, or one with an invalid prefix).

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #2
>Hi Alan,

You wrote: "if the validator returns false". The definition of the
client-side validation function requires that you set the args parameter's
IsValid property to true or false:
Yup, that was my sloppy explanation. Sorry about that.
function ValidateTxtDeliveryCountriesJS(source, args)
{
if (valid)
args.IsValid = true;
else
args.IsValid = false;
}

Note that names like args and IsValid are case sensitive.
I was setting args.Valid, not args.IsValid, which is why it didn't work.
I changed it and it worked fine.

Thanks very much
--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:bO**************@nospamthankyou.spam...
Hello,

I have a custom validator on my page, and have the server-side code
working fine. I want to add a client-side funtion as well, but am not sure
how to wire it in so that it works with the other validators on the page.

I specified the name of the Javascript function with the
ClientValidationFunction attribute of the custom validator, and it is
being called fine. However, if the validator returns false (ie bad data),
nothing happens on the client. With the other validators, I get a message
box popping up with the warnings, and I get the red text by the control so
the user can see which control fired the error.

How do I get the custom validator to do this? Here is the server tag...

<asp:CustomValidator ControlToValidate="txtDeliveryCountries"
OnServerValidate="ValidateTxtDeliveryCountries"
ClientValidationFunction="ValidateTxtDeliveryCount riesJS"
Display="Dynamic" Text="At least one country name does not start with U_,
E_ or W_" Runat="Server" />

(the point of the validator is that it checks a multiline textbox, that is
supposed to contain a list of countries, each of which has one of U_, E_
or W_ as a prefix. The validator checks to make sure they didn't enter a
country without a prefix, or one with an invalid prefix).

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)



--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
0
by: Harley | last post by:
Hello, I am just learning the tcp/ip functions etc under vb.net so please look over me if this is obviouse. I have been all over looking into any functions that I didn't totaly understand and...
8
by: Ankit Aneja | last post by:
i am doing here some some socket-client work in C# windows service it is working fine for multiple clients now i want to limit these multiple clients to 25 for example i want that when service...
2
by: Delmar | last post by:
I need to build Web Application that will generate a client to execute some operations. Each client has running silent application. Maybe somebody can advice me what can I do ? Thank you.
14
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
0
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <?php function...
2
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.