473,414 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

help with custom validators

112 100+
Hello there..

I have a custom validator for my text boxes. the code is as below..
Expand|Select|Wrap|Line Numbers
  1.  <asp:CustomValidator ID="CustomValidator3" runat="server" ControlToValidate="text1" 
  2.                                                     ErrorMessage="Please enter text1" 
  3.                                                     ClientValidationFunction="ClientValidate3" ValidateEmptyText="true" ValidationGroup="Submit" 
  4.                                                     onservervalidate="CustomValidator3_ServerValidate" Display="Dynamic" SetFocusOnError="false">*</asp:CustomValidator>  
Expand|Select|Wrap|Line Numbers
  1. function ClientValidate3(sender, args) {
  2.             var txt1 = document.getElementById("<%= text1.ClientID %>");
  3.             var txt2 = document.getElementById("<%= text2.ClientID %>");
  4.               if ((txt1.value == "" && txt2.value != ""))
  5.             {
  6.                 args.IsValid = false;
  7.             } else {
  8.                 args.IsValid = true;
  9.             }
  10.             if ((txt1.value == "" && txt2.value != ""))        
  11.             document.getElementById("<%= text1.ClientID%>").focus();
  12.         }
Expand|Select|Wrap|Line Numbers
  1. protected void CustomValidator3_ServerValidate(object source, ServerValidateEventArgs args)
  2.         {
  3.            if ((text1.Text == "" && text2.Text != ""))
  4.             {
  5.                 args.IsValid = false;
  6.             }
  7.             else
  8.             {
  9.                 args.IsValid = true;
  10.             }
  11.         }
now the problem is ..when I do not enter text in the other text box, the custom validator immediately gives me the error message but this error message does not clear out when the text is filled in the box and the cursor or focus moves away from it. This would confuse the user a lot as he/she can still see the error message even after the text box is filled. is it how the custom validator behaves or is there something that I can change in my code for this to happen..
can somebody please tell me..thank you
Apr 26 '10 #1
0 887

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
2
by: Rob | last post by:
I am developing an intranet application, that has to pass interanl security audit. The framework version that I am using is .Net framework version 1.1. Some combinations of text entered in any text...
6
by: jk | last post by:
Looking through WebUIValidation.js, I discovered that the standard validators don't cater for non-numeric date formats (e.g. dd-MMM-yyyy) which I would like to do To keep code to a minimum, I...
2
by: msnews.microsoft.com | last post by:
Hi All, I m facing a problem. As u know asp.net vallidators did not work in non-microsoft browsers. So for that i m using Server Side Solution. But i don't understand how can i show the...
5
by: Jason | last post by:
I am able fire my field validators in FireFox on the server side using... Page.Validate() If Not Page.IsValid Then Exit Sub End If But the it won't fire Custom Validators. Anybody know why?
5
by: Mattyw | last post by:
Hi, I'm relatively new to Web Forms, I have been using Required Field Validators and Regular Expression Validators on a Web Form I am developing and everything works as expected using Visual...
1
by: Ben | last post by:
i'm having trouble getting a custom validator to fire on one of my webforms. i dragged a custom validator onto the form, left all the properties on default, double clicked it, and typed this in the...
5
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
1
gagandeepgupta16
by: gagandeepgupta16 | last post by:
Hi I am working on an entry form using validation controls in ASP.NET. I have two controls which requires custom validators, no issue in using plain custom validators. But when i am using...
1
by: Steveaux | last post by:
Hi, I'm new to ASP.Net, so this may be something simple that I forgot. I have a form where a person can create a login. I'm doing the processing on this myself. The form has a plethora of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.