Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 22nd, 2005, 11:38 AM
Registered User
 
Join Date: Mar 2005
Location: Orlando, FL, USA.
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
Reply With Quote
  #2 (permalink)  
Old April 22nd, 2005, 11:50 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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?
Reply With Quote
  #3 (permalink)  
Old April 23rd, 2005, 03:59 AM
Authorized User
 
Join Date: Apr 2005
Location: Kuruman, Northern Cape, South Africa.
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!

Reply With Quote
  #4 (permalink)  
Old April 24th, 2005, 07:11 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:11 PM.


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