making validation happen only when a button is clicked

Discussion in 'ASP .Net' started by Humberto Alvarez, Aug 29, 2005.

  1. Hi All



    I'm using asp requiredfieldvalidator and regularexpressionvalidator to
    validate a text field and a file input field respectively. The validation
    messages (the text property of the validation controls) display when the
    controls to validate loose focus and not only when the submit button (with
    causesvalidation=true ) is pushed.



    I want these validation messages to display just when the button is pushed
    and not when the controls to validate loose focus. How could I do this?



    Thanks,

    Humberto
     
    Humberto Alvarez, Aug 29, 2005
    #1
    1. Advertising

  2. Humberto Alvarez

    Peter Blum Guest

    Hi Humberto,

    If you are attempting to get client-side validation when the user submits,
    then you cannot do this with the ASP.NET validators. Its not supported. My
    replacement to the ASP.NET validators, Professional Validation And More
    (http://www.peterblum.com/vam/home.aspx), does support this. Each of its 25
    validators has a property called EventsThatValidate that can be set to
    "onchange", "onsubmit", or "both" (the default).

    If you elect to abandon client side validation, its easy. Just set each
    validator's EnableClientScript property to false. Now the button's OnClick
    method will validate for you, only after a post back. (Don't forget to
    ALWAYS test Page.IsValid is true inside the Click event method before
    saving.)

    Here's the problem. The file input field will not pass along the file path
    in its textbox field to the server side when using <form
    enctype="multipart/form-data" > which is normally done with <input
    type=file> tags.

    That means the RegularExpressionValidator will not have anything to evaluate
    on post back. You cannot test that the user added a specific file extension,
    for example. The usual rule is to evaluate the contents of the file passed
    to you to be sure its the desired format (and virus free!). You can use a
    CustomValidator to run your own code that does this and report errors back
    to the user.

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

    "Humberto Alvarez" <> wrote in message
    news:...
    > Hi All
    >
    >
    >
    > I'm using asp requiredfieldvalidator and regularexpressionvalidator to
    > validate a text field and a file input field respectively. The validation
    > messages (the text property of the validation controls) display when the
    > controls to validate loose focus and not only when the submit button (with
    > causesvalidation=true ) is pushed.
    >
    >
    >
    > I want these validation messages to display just when the button is pushed
    > and not when the controls to validate loose focus. How could I do this?
    >
    >
    >
    > Thanks,
    >
    > Humberto
    >
    >
     
    Peter Blum, Aug 29, 2005
    #2
    1. Advertising

  3. Humberto Alvarez

    Peter Blum Guest

    FYI: I answered this on your cross posting in the
    public.dotnet.framework.aspnet newsgroup.

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

    "Humberto Alvarez" <> wrote in message
    news:...
    > Hi All
    >
    >
    >
    > I'm using asp requiredfieldvalidator and regularexpressionvalidator to
    > validate a text field and a file input field respectively. The validation
    > messages (the text property of the validation controls) display when the
    > controls to validate loose focus and not only when the submit button (with
    > causesvalidation=true ) is pushed.
    >
    >
    >
    > I want these validation messages to display just when the button is pushed
    > and not when the controls to validate loose focus. How could I do this?
    >
    >
    >
    > Thanks,
    >
    > Humberto
    >
    >
     
    Peter Blum, Aug 29, 2005
    #3
    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. djjohnst
    Replies:
    0
    Views:
    362
    djjohnst
    Jun 6, 2007
  2. Replies:
    1
    Views:
    393
    =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?=
    Aug 22, 2007
  3. Humberto Alvarez

    making validation happen only when a button is clicked

    Humberto Alvarez, Aug 29, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    100
    Humberto Alvarez
    Aug 29, 2005
  4. Claire Osborne
    Replies:
    3
    Views:
    141
    Michael Winter
    Feb 10, 2004
  5. Replies:
    8
    Views:
    132
    Thomas 'PointedEars' Lahn
    Nov 30, 2005
Loading...

Share This Page