473,320 Members | 1,920 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,320 software developers and data experts.

Simple problem with a Custom Validator

Hi All,

I'm having problems getting a custom validator to work. I'm hoping someone
could perhaps notice what I've missed. I only want to provide a server side
validation method. The problem is basically that the method that I've designated
as the validation routine never gets called so I can't do anything about
potentially duff data.

I've declared the custom control as:

<asp:customvalidator id=valDoB runat="server" controltovalidate="txtDoB"
errormessage="Please ensure a valid date has been provided in the DoB field"
onservervalidate="valDoB_ServerValidate" EnableClientScript="False">*</asp:customvalidator>

Then I have a method called valDob_ServerValidate

public void valDoB_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs
args) {
if(txtDoB.Text == String.Empty){
valDoB.ErrorMessage = "Please ensure that the DoB field has been filled
in";
}
}
If anyone can spot what I've missed I would be very greatful

Thanks all

tce

Nov 19 '05 #1
2 1627
Couple things.

If you use an inner text and and error message, it won't work quite the
same. Stick with one or the other, unless you are using a summary
validator.

The CustomValidator will NOT call your validation method if the textbox is
empty. You will need to use a RequiredFieldValidator for this.

You validate method should look something like this. The args.IsValid
property actually determines whether validation fails for the page. It is
true by default, so you must make it false.

validate( .. )
{
if ( args.Value != "hello" )
args.IsValid = false;
}

HTH,

bill
"SimonH" <no**@hotmail.com> wrote in message
news:34*********************@news.microsoft.com...
Hi All,

I'm having problems getting a custom validator to work. I'm hoping someone
could perhaps notice what I've missed. I only want to provide a server side validation method. The problem is basically that the method that I've designated as the validation routine never gets called so I can't do anything about
potentially duff data.

I've declared the custom control as:

<asp:customvalidator id=valDoB runat="server" controltovalidate="txtDoB"
errormessage="Please ensure a valid date has been provided in the DoB field" onservervalidate="valDoB_ServerValidate" EnableClientScript="False">*</asp:customvalidator>
Then I have a method called valDob_ServerValidate

public void valDoB_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args) {
if(txtDoB.Text == String.Empty){
valDoB.ErrorMessage = "Please ensure that the DoB field has been filled
in";
}
}
If anyone can spot what I've missed I would be very greatful

Thanks all

tce

Nov 19 '05 #2
Hi Bill

Thanks for your reply. I'm not sure why but I went home last night with it
broken and then it started working on the first new build this morning.

Havent a clue why.

The info you've provided is helpful though so thank you

Simon
Couple things.

If you use an inner text and and error message, it won't work quite
the same. Stick with one or the other, unless you are using a summary
validator.

The CustomValidator will NOT call your validation method if the
textbox is empty. You will need to use a RequiredFieldValidator for
this.

You validate method should look something like this. The args.IsValid
property actually determines whether validation fails for the page.
It is true by default, so you must make it false.

validate( .. )
{
if ( args.Value != "hello" )
args.IsValid = false;
}
HTH,

bill
"SimonH" <no**@hotmail.com> wrote in message
news:34*********************@news.microsoft.com...
Hi All,

I'm having problems getting a custom validator to work. I'm hoping
someone could perhaps notice what I've missed. I only want to provide
a server

side
validation method. The problem is basically that the method that I've

designated
as the validation routine never gets called so I can't do anything
about potentially duff data.

I've declared the custom control as:

<asp:customvalidator id=valDoB runat="server"
controltovalidate="txtDoB" errormessage="Please ensure a valid date
has been provided in the DoB

field"
onservervalidate="valDoB_ServerValidate"

EnableClientScript="False">*</asp:customvalidator>
Then I have a method called valDob_ServerValidate

public void valDoB_ServerValidate(object source,

System.Web.UI.WebControls.ServerValidateEventArgs
args) {
if(txtDoB.Text == String.Empty){
valDoB.ErrorMessage = "Please ensure that the DoB field has been
filled
in";
}
}
If anyone can spot what I've missed I would be very greatful

Thanks all

tce

Nov 19 '05 #3

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

Similar topics

8
by: Spartanicus | last post by:
The document at http://homepage.ntlworld.com/spartanicus/custom_dtd.htm uses a custom DTD, the w3c validator validates it but with this warning: "Unknown Parse Mode! The MIME Media Type...
2
by: Evgueni | last post by:
Hello, I am new to .NET, and a custom validator is giving me a lot of grief. I want to use a Custom Validation control and for some reasons it's not firing the validation procedure. I am using...
1
by: Vinod I | last post by:
Hi Team, I made a custom validator control which is having 2 public properties. But after making dll & adding that to the ToolBox, I could not able to find these properties in Property Box. ...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
5
by: Mattyw | last post by:
Hi, I'm relatively new to Web Forms, I have been using Required Field Validators and Regular Expression Validators on a Web Form I am developing and everything works as expected using Visual...
2
by: Alan Silver | last post by:
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...
3
by: Andy | last post by:
Hi folks, I have a customvalidator control that works properly if it isn't contained in an ASP:TABLE. But, when I place it inside an ASP:TABLE, I find that _ServerValidate doesn't get fired,...
4
by: Rick | last post by:
Hello, I built a composite web control that has a textbox and a date control. added my custom control on a webform where there are other standard controls. Each control on the form has a...
1
gagandeepgupta16
by: gagandeepgupta16 | last post by:
Hi I am working on an entry form using validation controls in ASP.NET. I have two controls which requires custom validators, no issue in using plain custom validators. But when i am using...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.