Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 November 29th, 2003, 06:52 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple Control Validation

I have 3 textboxes whose values are required to add up to 100. I am able to easily implement a javascript solution on the client.
However, I tried to use a simple routine in the code behind that went like this:
   Dim total As Integer
        total = CInt(TextBox1.Text) + CInt(TextBox2.Text) + _
                CInt TextBox3.Text)
        If total = 100 Then
            lblMsg.Visible = False
        Else
            lblMsg.Visible = True
        End If

Where lblMsg is error text. This proved unreliable, sometimes revealing the error message when total was indeed 100, sometimes leaving it invisible when it was not equal to 100.

I've given up on validation controls, as it seems they are only geared to validating one control at a time. Any ideas?

 
Old November 29th, 2003, 11:13 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can still use validation controls even though they seem to only validate one control. Set up a custom validator and create the handler for it. Then do your validation test based on the three controls. Set the validator validity based on the result.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 1st, 2003, 11:26 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I took your advice and created a client function in Javascript to handle the validation. The validator needed a control to validate, so I created another textbox to store the sum value. I think I may be missing your point; are your suggesting a code behind function (server-side) instead?

Here's what I added: The Custom Validator (cleverly named)

<asp:CustomValidator id="CustomValidator1" style="Z-INDEX: 106; LEFT: 241px; POSITION: absolute; TOP: 225px" runat="server" ErrorMessage="Must add up to 100" ClientValidationFunction="PercentSum" ControlToValidate="TextBox4"></asp:CustomValidator>

And here is the client function:

<script language="javascript">
    function PercentSum(source, arguments){
        var theform = document.Form1;
        var a = parseInt(theform.TextBox1.value);
        var b = parseInt(theform.TextBox2.value);
        var c = parseInt(theform.TextBox3.value);
        document.Form1.TextBox4.value = a + b + c;
        var total = document.Form1.TextBox4.value;

        if(total == 100){
            arguments.IsValid = true;
        }else{
            arguments.IsValid = false;
        }
    }
    </script>

 
Old December 2nd, 2003, 09:37 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter-

Upon further review...
Ok, I get it now. The Custom validator is set to validate one of the textboxes, but the handler for the validator works with all 3 values and their total.

I implemented and tested this just now, and it works just as you described. Thanks a bunch, Peter (my best Lumbergh voice).

Hey Peter man turn on channel 9, check out this chick!

Sorry, couldn't help myself. You assistance is much appreciated.

-Colonel
 
Old December 2nd, 2003, 10:42 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

:D LOL





Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple email validation (different format) kumiko Javascript 2 July 22nd, 2008 08:06 AM
Multiple emails validation in one text box with co kumiko Javascript 5 February 7th, 2008 05:49 AM
SAX Validation against multiple XSDs in MSXML Satnam XML 0 August 29th, 2006 04:11 AM
Validation control divsalar ASP.NET 1.x and 2.0 Application Design 1 December 25th, 2004 12:22 PM
Validation control ? basant ADO.NET 1 February 5th, 2004 04:46 AM





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