ControlToValidate

Discussion in 'ASP .Net Web Controls' started by Kevin Humphreys, Feb 14, 2007.

  1. 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.
     
    Kevin Humphreys, Feb 14, 2007
    #1
    1. Advertising

  2. Kevin Humphreys

    marss Guest

    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/d...webuiwebcontrolscustomvalidatorclasstopic.asp
     
    marss, Feb 15, 2007
    #2
    1. Advertising

  3. 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.

    "marss" <> wrote in message
    news:...
    >
    > 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/d...webuiwebcontrolscustomvalidatorclasstopic.asp
    >
     
    Kevin Humphreys, Feb 15, 2007
    #3
  4. Kevin Humphreys

    marss Guest

    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
     
    marss, Feb 16, 2007
    #4
  5. Got it. Thanks a lot.

    "marss" <> wrote in message
    news:...
    >
    > 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
    >
     
    Kevin Humphreys, Feb 19, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Nagy

    Custom Control needs ControlToValidate

    Steven Nagy, Mar 6, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    605
    MasterGaurav \(www.edujini-labs.com\)
    May 8, 2007
  2. DaveyP
    Replies:
    1
    Views:
    705
    Chris Shepherd
    Apr 18, 2008
  3. Nathan Sokalski
    Replies:
    1
    Views:
    411
    bruce barker
    May 20, 2008
  4. Nathan Sokalski
    Replies:
    0
    Views:
    371
    Nathan Sokalski
    Mar 8, 2010
  5. Donal McWeeney

    custom validator and ControlToValidate in a composite control...

    Donal McWeeney, Sep 28, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    236
    Donal McWeeney
    Sep 29, 2004
Loading...

Share This Page