Home All Groups Group Topic Archive Search About
Author
14 Feb 2007 5:18 PM
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.

Author
15 Feb 2007 8:26 AM
marss
Kevin Humphreys wrote:
> 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/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolscustomvalidatorclasstopic.asp
Author
15 Feb 2007 3:34 PM
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.

Show quoteHide quote
"marss" <marss***@gmail.com> wrote in message
news:1171528011.932166.287010@k78g2000cwa.googlegroups.com...
>
> Kevin Humphreys wrote:
>> 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/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolscustomvalidatorclasstopic.asp
>
Author
16 Feb 2007 7:54 AM
marss
Kevin Humphreys wrote:
> 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
Author
19 Feb 2007 12:11 PM
Kevin Humphreys
Got it. Thanks a lot.

Show quoteHide quote
"marss" <marss***@gmail.com> wrote in message
news:1171612467.298556.269520@v45g2000cwv.googlegroups.com...
>
> Kevin Humphreys wrote:
>> 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
>