Display a message if client validation fails?
I'm working on an application form for a website which implements ASP.NET validation (including client side).
I have a requirement to display a message at the bottom of the page if the client validation fails. Something along the lines of "Please go back and check your answers".
The problem is, t开发者_如何学Pythonhe submit button's OnClientClick event obviously fires before the client validation.
Any idea how I can get around this problem?
On your RequiredFieldValidator
if you use both the ErrorMessage
and Text
attributes the value of ErrorMessage
will appear in the ValidationSummary
, while the value of Text
will appear at the location of the RequiredFieldValidator
.
E.g.:
<RequiredFieldValidator
ErrorMessage="This will appear in the summary at the bottom of the page."
Text="This will appear in the middle of the page."
.../>
So to hide the ErrorMessage
from the summary simply set it to an empty string:
ErrorMessage=""
Have you set the CausesValidation
property on your button?
What is your OnClientClick
method doing?
As I understand it you are trying to reinvent the wheel by implementing you own functionality to display the validation message. You should use a ValidationSummary
control to display the message to the user. And you should also remove your custom OnClientClick
function.
精彩评论