473,503 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2338
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
3705
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
2415
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
2626
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
3123
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
1039
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
8231
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
3768
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
19396
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
4364
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
2897
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...
0
7202
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
7086
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
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
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
7460
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
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.