ASP.NET validation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin

    ASP.NET validation

    Hi all

    Can anyone please tell me how to perform validation an a control based on a value in another control. i.e. If control A == "Hello" then perform validation on control B, otherwise don't perform the validation on control
    any ideas

    Thanks eveeryon

    Kevin
  • Ignacio Machin \( .NET/ C#  MVP \)

    #2
    Re: ASP.NET validation

    Hi Kevin,

    This depend of your page logic, what I do in a case like this is have a
    method in the code behind page which I call before the action I will
    perform, in the method I do all the checking I need if it's failed I make
    visible a label in the page with the error description, you could even put
    the focus in the failing control if you want using Javascript.

    then in the handler the first thing I do is check if the validation passed,
    if not just return or do what you need.

    void ProcessClick(.. . )
    {
    if ( !CheckControls( ) )
    return;


    Cheers,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation

    "Kevin" <anonymous@disc ussions.microso ft.com> wrote in message
    news:108C67E3-B7D3-4E14-B287-9CC24DF9240F@mi crosoft.com...[color=blue]
    > Hi all,
    >
    > Can anyone please tell me how to perform validation an a control based on[/color]
    a value in another control. i.e. If control A == "Hello" then perform
    validation on control B, otherwise don't perform the validation on control B[color=blue]
    > any ideas?
    >
    > Thanks eveeryone
    >
    > Kevin[/color]


    Comment

    • Martin Marinov

      #3
      Re: ASP.NET validation

      On of the solution to do this is to use CustomValidator control

      private void controlA_Server Validate(object source,
      System.Web.UI.W ebControls.Serv erValidateEvent Args args)
      {
      if ( control A == "Hello" )
      {
      if (perform validation on the second control is true)
      {
      args.IsValid = true;
      }
      else
      {
      args.IsValid = false;
      }
      }
      }

      "Kevin" <anonymous@disc ussions.microso ft.com> wrote in message
      news:108C67E3-B7D3-4E14-B287-9CC24DF9240F@mi crosoft.com...[color=blue]
      > Hi all,
      >
      > Can anyone please tell me how to perform validation an a control based on[/color]
      a value in another control. i.e. If control A == "Hello" then perform
      validation on control B, otherwise don't perform the validation on control B[color=blue]
      > any ideas?
      >
      > Thanks eveeryone
      >
      > Kevin[/color]


      Comment

      Working...