Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 December 15th, 2004, 10:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default Custom Validation Control Client side event

Hi,

A have the need for a custom validation control to test the comination of a textbox being checked and that a field is not left blank.
It appears that the custom validation event does not fire when the ControlToValidate is left blank.
I cant use the RequiredFieldValidator because it does not allow me to test the checkbox.

I guess I could put in a hidden textbox and use it as the ControlToValidate with some content just to fire the client event.
And then test the correct field length throught javascript ignoring the args.Value of the validator.

BUT this seems like a poor method.
Doen anyone know the correct way to do this.

An simplified example of the situation is below.
This ignores the checkbox situation but if the code is run you will see that the client side event only fires when something is in the textbox.

Code:
<HTML>
  <HEAD>

        <script language="JavaScript">
function validateNumber(oSrc, args) {
alert('Boo');
args.IsValid = (args.Value.length > 3);
}
        </script>
</HEAD>
    <body>
        <form runat="server" ID="Form1">
            <p>
                Number:
                <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
                &nbsp;
                <asp:CustomValidator id="CustomValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="The input must have at least 4 characters"
                    ClientValidationFunction="validateNumber"></asp:CustomValidator>
            </p>
            <p>
                <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
            </p>
            <p>
                <asp:Label id="Label1" runat="server"></asp:Label>
            </p>
        </form>
    </body>
</HTML>
Any assistance would be appreciated

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old December 16th, 2004, 01:38 AM
Authorized User
 
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have exactly same problem. I need to test two textboxes. If you look at my thread that is still active:-
http://p2p.wrox.com/topic.asp?TOPIC_ID=23253

I cannot use customvalidator or requiredfield validator. I am planning to test it on the server side. Let me know if you find a better solution. I guess this is the only solution.

 
Old December 16th, 2004, 06:12 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by Renu


I cannot use customvalidator or requiredfield validator...
Hi again,
no,you can use them but in server-side(now in server-side you cant show po pup window anymore).

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old December 17th, 2004, 08:47 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Rod,
There are two ways in this regard,
1-you want to validate them on the serve-side,
2-you want to validate them on the client-side,
it's clear checking them on the client-side results in better performance,so if you want to work-
on the client-side it's better to ignore such validators and work just with JavaScript,there would
be no need for hidden textboxes anymore,
but if you want to work on the server-side,you can use such validators easier,
(but ignore client-side facilities like showing po pup windows and ...),
(for more info you can have a look at Renu's thread).

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Is client-side validation in ASP.NET 2.0 possible? jacob ASP.NET 2.0 Basics 6 April 10th, 2007 05:07 AM
Client Side Validation anujrathi ASP.NET 1.0 and 1.1 Professional 1 June 17th, 2006 10:23 PM
Posting form After Custom Client-side validation rathbird General .NET 3 March 4th, 2004 06:03 PM





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