473,378 Members | 1,542 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,378 software developers and data experts.

Custom validation

I have 2 <asp:textbox controls>:

<asp:textbox id="txt1" Runat="server" ></asp:textbox>

<asp:textbox id="txt2" Runat="server" ></asp:textbox>

User must insert the value either in txt1 OR in txt2, so one of them
shouldn't be empty.

So I use custom validator:

<asp:CustomValidator id="valPhone" Runat="server" ErrorMessage="You must
insert text1 or text2!"
ControlToValidate="txt2"
Display="Dynamic"></asp:CustomValidator>

AND server:

Private Sub valPhone_ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs) Handles
valPhone.ServerValidate
If txt1.Text = "" And txt2.Text = "" Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub

The server validation is fired only if there is some value in txt2 box.If
txt2.text is empty then server validation is not fired.
How can I solve this problem?

I would like also to include client validation.

Thank you,
Simon
Nov 18 '05 #1
3 2331
Hi Simon,

An empty field is a valid input for a custom validator! I think there
is the possibility to leave the ControlToValidate field blank, but I
haven't tried it yet.

See:

http://msdn.microsoft.com/library/de...pplusvalid.asp
Regards
Johannes

On Thu, 27 May 2004 09:55:32 +0200, "simon"
<si*********@stud-moderna.si> wrote:
I have 2 <asp:textbox controls>:

<asp:textbox id="txt1" Runat="server" ></asp:textbox>

<asp:textbox id="txt2" Runat="server" ></asp:textbox>

User must insert the value either in txt1 OR in txt2, so one of them
shouldn't be empty.

So I use custom validator:

<asp:CustomValidator id="valPhone" Runat="server" ErrorMessage="You must
insert text1 or text2!"
ControlToValidate="txt2"
Display="Dynamic"></asp:CustomValidator>

AND server:

Private Sub valPhone_ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs ) Handles
valPhone.ServerValidate
If txt1.Text = "" And txt2.Text = "" Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub

The server validation is fired only if there is some value in txt2 box.If
txt2.text is empty then server validation is not fired.
How can I solve this problem?

I would like also to include client validation.

Thank you,
Simon


Nov 18 '05 #2
Try getting rid of the ControlToValidate property. It's not necessary
for a CustomValidator, and in this case, it may be what is preventing
the ServerValidate event from firing.

For client-side validation, use the ClientValidationFunction property
of the CustomValidator.
"simon" <si*********@stud-moderna.si> wrote in message news:<#9**************@TK2MSFTNGP09.phx.gbl>...
I have 2 <asp:textbox controls>:

<asp:textbox id="txt1" Runat="server" ></asp:textbox>

<asp:textbox id="txt2" Runat="server" ></asp:textbox>

User must insert the value either in txt1 OR in txt2, so one of them
shouldn't be empty.

So I use custom validator:

<asp:CustomValidator id="valPhone" Runat="server" ErrorMessage="You must
insert text1 or text2!"
ControlToValidate="txt2"
Display="Dynamic"></asp:CustomValidator>

AND server:

Private Sub valPhone_ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs) Handles
valPhone.ServerValidate
If txt1.Text = "" And txt2.Text = "" Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub

The server validation is fired only if there is some value in txt2 box.If
txt2.text is empty then server validation is not fired.
How can I solve this problem?

I would like also to include client validation.

Thank you,
Simon

Nov 18 '05 #3
Hi,

If I get rid of the ControlToValidate property then validation function is
executed but when I set
args.isValid=false, nothing happened.
It just pass by like if I set args.isValid=true.
No difference.
Any idea?

Thank you,
Simon
"DujHoD" <J2********@aol.com> wrote in message
news:76**************************@posting.google.c om...
Try getting rid of the ControlToValidate property. It's not necessary
for a CustomValidator, and in this case, it may be what is preventing
the ServerValidate event from firing.

For client-side validation, use the ClientValidationFunction property
of the CustomValidator.
"simon" <si*********@stud-moderna.si> wrote in message

news:<#9**************@TK2MSFTNGP09.phx.gbl>...
I have 2 <asp:textbox controls>:

<asp:textbox id="txt1" Runat="server" ></asp:textbox>

<asp:textbox id="txt2" Runat="server" ></asp:textbox>

User must insert the value either in txt1 OR in txt2, so one of them
shouldn't be empty.

So I use custom validator:

<asp:CustomValidator id="valPhone" Runat="server" ErrorMessage="You must insert text1 or text2!"
ControlToValidate="txt2"
Display="Dynamic"></asp:CustomValidator>

AND server:

Private Sub valPhone_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
valPhone.ServerValidate
If txt1.Text = "" And txt2.Text = "" Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub

The server validation is fired only if there is some value in txt2 box.If txt2.text is empty then server validation is not fired.
How can I solve this problem?

I would like also to include client validation.

Thank you,
Simon

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Barbara Alderton | last post by:
I setup some standard Required Field Validation controls and one Custom validation control on an ASP.NET page (within a user control) to validate text entry. I also setup a Summary Control to post...
1
by: Stephen Adam | last post by:
Hi there, I have written a custom validation control which checks to see of an input field is not empty and contains only numeric data. I was using a regular expression validation control but...
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...
9
by: wardy1975 | last post by:
Hi All, Looking for a little expert advice on a few web standards issues. I am currently trying to understand the impact of web standards for a web application I work with. I have been doing a...
0
by: Marek | last post by:
Hi all, I have custrom control with four elements: text box, regular expression validator, required field validator and custom validator. Next this control is dragged on to web site with several...
3
by: Andy | last post by:
Hi folks, I have a customvalidator control that works properly if it isn't contained in an ASP:TABLE. But, when I place it inside an ASP:TABLE, I find that _ServerValidate doesn't get fired,...
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...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.