ControlToValidate

K

Kevin Humphreys

Hi There,
I am trying to implement the following criteria for the controltovalidate
web control.
If a checkbox is checked and a textbox is empty then accept the validation
as true and process some code if the page is valid
If a checkbox is unchecked and a textbox is empty then treat the validation
as false and not allow to process some more code.

Any ideas?

Thanks,
Kevin.
 
M

marss

Kevin said:
Hi There,
I am trying to implement the following criteria for the controltovalidate
web control.
If a checkbox is checked and a textbox is empty then accept the validation
as true and process some code if the page is valid
If a checkbox is unchecked and a textbox is empty then treat the validation
as false and not allow to process some more code.

Any ideas?

Thanks,
Kevin.

Use CustomValidator.
http://msdn.microsoft.com/library/d...webuiwebcontrolscustomvalidatorclasstopic.asp
 
K

Kevin Humphreys

Hi,
Thanks for this. However the custom validator also validates based on 1
control only.
I am trying to validate based on the criteria of 2 controls.

Any Ideas?

Thanks,
Kevin.
 
M

marss

Kevin said:
Hi,
Thanks for this. However the custom validator also validates based on 1
control only.
I am trying to validate based on the criteria of 2 controls.

Any Ideas?

Thanks,
Kevin.

Hi,
The CustomValidator implements custom validation irregardless of the
control's number.
Example.
..ascx
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="Error!"
OnServerValidate="CustomValidator1_ServerValidate"></
asp:CustomValidator>

..cs
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
if (CheckBox1.Checked)
args.IsValid = TextBox1.Text.Length == 0;
else
args.IsValid = TextBox1.Text.Length > 0;
}

Regards,
Mykola
 
K

Kevin Humphreys

Got it. Thanks a lot.

marss said:
Hi,
The CustomValidator implements custom validation irregardless of the
control's number.
Example.
.ascx
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="Error!"
OnServerValidate="CustomValidator1_ServerValidate"></
asp:CustomValidator>

.cs
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
if (CheckBox1.Checked)
args.IsValid = TextBox1.Text.Length == 0;
else
args.IsValid = TextBox1.Text.Length > 0;
}

Regards,
Mykola
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top