Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 22nd, 2005, 11:38 AM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default custom validator question

I am using a custom validator on a web form. I am using the following code:

private void CheckRom()
        {
            int to = int.Parse(romToText.Text);
            int from = int.Parse(romFromText.Text);
            if (romCheck.Checked == true && romFromText.Text != null && romToText != null)
            {
                if (to < from)
                {
                    validateROM.ErrorMessage = "The TO amount must be Greater than the FROM amount!";
                    validateROM.IsValid = true;

                }
                else
                {
                    validateROM.IsValid = false;
                }
            }

However, when running the code, the validator never fires. Can anyone help with the code to make this happen?

Thanks,

Dave

KSCDAVE
 
Old April 22nd, 2005, 11:50 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

AFAIK, you should have your validation function accept two parameters, and then set the second argument to true of false depending on your logic inside the function:

function CheckRom(oSrc, args)
{
if (someThing)
{
    // Valid
    args.IsValid = true;
}
else
{
    args.IsValid = false;
}
}

This also promotes reuse as you can use the same validation method for more than one control.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Record Companies by Tricky (Track 12 from the album: Angels With Dirty Faces) What's This?
 
Old April 23rd, 2005, 03:59 AM
Authorized User
 
Join Date: Apr 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to EricJ
Default

You can just use the return-statement in your vbscript rather than rewriting your code in javascript!

 
Old April 24th, 2005, 07:11 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I just realized you were working on a server side method and not a client side JavaScript function.

For server side validation, try this:

private void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{

}

Create a method with this signature (e.g. have it accept an object and a ServerValidateEventArgs).
Just as with my JavaScript example, set the IsValid property of the args argument to either true or false.

To make this work, hook up the ServerValidate of your CustomValidator to this method:

this.CustomValidator1.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandl er(this.CustomValidator1_ServerValidate);

That should do the trick. If not, can you provide more detail about your current code?

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Your Eyes Open by Keane (Track 6 from the album: Hopes and Fears) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
DDL Custom Validator AspNetGuy BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 6th, 2008 05:17 PM
Custom Validator against a database Steve Spicer ASP.NET 2.0 Professional 16 January 12th, 2008 06:25 AM
Custom Validator for Two text box. vickyhere ASP.NET 1.0 and 1.1 Basics 2 October 15th, 2004 06:41 AM
Custom Validator bmains ASP.NET 1.0 and 1.1 Basics 4 December 18th, 2003 11:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.