newbie seeks CustomValidation advice/problem solving...

G

Guest

Hi all,

Hoping someone can help me w/an annoying issue.

I'm using a CustomValidator to check the length of a value in a textbox
(length should be less than 500).

When I test the form, if length > 500, I get the appropriate error message
from the CustomValidation. When I replace the text in the textbox w/length <
500 chars and click submit, the form refreshes and the error message
disappears, but the form doesn't get submitted. I have to click "submit" a
second time and I get the expected result.

Can someone help me "submit" on first click please?

My code:

protected void cvTxtMessage_ServerValidate(object source,
ServerValidateEventArgs args)
{
if (args.Value.Length < 500)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}

my HTML:

<asp:CustomValidator
ID="cvTxtMessage"
runat="server"
ControlToValidate="txtFeedbackBody"
Display="Dynamic"
ErrorMessage="* Message length exceeds 500 characters.
Please shorten your message."
OnServerValidate="cvTxtMessage_ServerValidate" />

Thanks!
 
P

Peter Blum

Your server side function looks fine. But since the problem occurs before it
posts back, there must be something wrong with the client-side system.
First, use the first topic of this article to make sure client-side
validation is properly installed: http://aspalliance.com/699.

Now here's a client-side function to do the same thing:
<script language='javascript'>
function TxtMsgLength(source, args)
{
args.IsValid = args.Value.length < 500;
}
</script>
Set CustomValidator.ClientValidationFunction = "TxtMsgLength"


--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
G

Guest

Thanks. I'll check out the article, but can you tell me: Is it neccessary to
add client AND server-side validation all the time?
 
G

Guest

Also, I'm on an ASP.NET 2.0 environment. I see from your article that it's
not neccessary to deal w/client-side validation. True?
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top