Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 October 6th, 2005, 11:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ~Bean~
Default Validate Multiple Textboxes

I have 3 textboxes on a form whose values need to add up to 100. How can I validate this using a required field (or custom) validator?

-------------------------
Beware of programmers with screwdrivers...
__________________
-------------------------
Beware of programmers with screwdrivers...
 
Old October 10th, 2005, 11:55 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

   I don't know how you could do that with a custom validator. I would suggest just adding the values on a button click, if the values add up to 100, do additional processing, otherwise display an error message.

Jim

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

On the contrary; a custom validator is ideal for such a task. See here:

http://msdn.microsoft.com/library/de...ClassTopic.asp

Basically, you need to do this:

1. Add the validator

2. Set the client side function with ClientValidationFunction

3. Create a JavaScript function with this signature:

function ValidationFunctionName(source, arguments)
{}

4. Inside the function, get a reference to the other controls you want to validate and get their values. Calculate whatever you need to do. In the end, set the IsValid property of the arguments parameter to either true or false.

5. Repeat the validation inside the server side function.

That's about it.

Have fun.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Validate multiple email addresses mat41 Javascript 1 August 29th, 2007 12:45 AM
textboxes or list boxes with multiple fore color svharishtech Pro VB 6 5 April 20th, 2007 05:04 PM
Help: character and multiple textboxes snoopy_sweden Javascript How-To 0 February 20th, 2007 04:08 AM
Using loop to change text of multiple textboxes snowy0 VB.NET 6 July 29th, 2004 08:54 AM





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