473,472 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

CUSTOMVALIDATOR works but page goes on on FALSE

Hola

I have this customvalidator

<asp:CustomValidator id="ComboValidator" runat="server"
ErrorMessage="CustomValidator" /> (The OnServerValidate method is set in
Events windows of the Control Property)
THIS IS THE METHOD
private void ValidarCombo(object sender, ServerValidateEventArgs e)
{
int counter=0;
foreach(Control control in this.Controls[1].Controls)
{
if(control.GetType().ToString().IndexOf("DropDownL ist")!=-1)
{
DropDownList combo=(DropDownList)control;
if(combo.SelectedItem.Value=="---")
{
counter++;
}
}
}
e.IsValid=(counter==0);
counter++;
}

It works perfectly. If a DropDownList is not selected, e.Valid is set to
false and also Page.IsValid BUT the page continues as if it was TRUE. Am I
missing something??
Thanks in advance
Nov 17 '05 #1
1 1363
Two things:

1. You must *always* test Page.IsValid in your Click event method before
saving. The Click event method gets called whether IsValid is true or false.
So its up to you to stop it from running your Save code.

2. If you are trying to prevent saving a "no selection" state, you can use
the RequiredFieldValidator. Just set its InitialText property to the value
of the no selection item. ("---" in your case, I think.)

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Jose Fernandez" <pp*****@hotmail.com> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
Hola

I have this customvalidator

<asp:CustomValidator id="ComboValidator" runat="server"
ErrorMessage="CustomValidator" /> (The OnServerValidate method is set in
Events windows of the Control Property)
THIS IS THE METHOD
private void ValidarCombo(object sender, ServerValidateEventArgs e)
{
int counter=0;
foreach(Control control in this.Controls[1].Controls)
{
if(control.GetType().ToString().IndexOf("DropDownL ist")!=-1)
{
DropDownList combo=(DropDownList)control;
if(combo.SelectedItem.Value=="---")
{
counter++;
}
}
}
e.IsValid=(counter==0);
counter++;
}

It works perfectly. If a DropDownList is not selected, e.Valid is set to
false and also Page.IsValid BUT the page continues as if it was TRUE. Am I
missing something??
Thanks in advance

Nov 17 '05 #2

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

Similar topics

2
by: Stephen Miller | last post by:
Can the CustomValidator be used to simply report unexpected errors, without requiring Client/Server validation? To explain, say you had a simple text box and button that did a Full-text Search of a...
1
by: Jose Fernandez | last post by:
Hola I have this customvalidator <asp:CustomValidator id="ComboValidator" runat="server" ErrorMessage="CustomValidator" /> (The OnServerValidate method is set in Events windows of the Control...
1
by: Beffmans | last post by:
Hi I have defined an customvalidator on my TextBox: function clientvalidate(source, arguments){ { // even number? if (arguments.Value%2 == 0) arguments.IsValid = true; else
0
by: bauer.todd | last post by:
The following page works fine on FireFox (the custom validator checks to make sure that there's a value in the file upload text box). However, on IE 7, when there's a value in the text box, the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.