making validation happen only when a button is clicked

H

Humberto Alvarez

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
 
P

Peter Blum

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: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top