How do I make an ASP button clickable after field validation fails?

I have an asp button:
btnSave.Attributes.Add("OnClick", "return isValidPhoneNumber('" & tbPhoneNum.Text & "','" & lblErrorMessage.ClientID & "')")

My JavaScript validation works but when it returns false the Save button is locked even after entering a valid phone number into the textbox.  How can I make the button clickable even when validaton fails?
nightshadzAsked:
Who is Participating?
 
Anurag ThakurConnect With a Mentor Technical ManagerCommented:
dont pass the tbPhoneNum.Text  to the function instead pass the client id of the control to the javascript and then from the client id get the text and validate it

this might help
0
 
Anurag ThakurTechnical ManagerCommented:
return true from the javascript function
0
 
nightshadzAuthor Commented:
That will cause a postback and save even invalid entries.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Anurag ThakurTechnical ManagerCommented:
sorry wrong suggestion ....
you have only one level of validation?
or one more level of validation in code behind
if yes then you can try to call the save only when Page.IsValid property is true
0
 
nightshadzAuthor Commented:
Validation takes place ONLY in JavaScript.  The call to the validation function is done in the OnClick attribute of the Save button (btnSave) as shown above.  When the JS validation fails and returns false, I can no longer click the Save button even if I enter the correct format into the textbox.  I'm trying to figure out how to not disable/lock btnSave if the validation returns false.
0
 
Anurag ThakurTechnical ManagerCommented:
what action are you taking - are you disabling the save button if the validation fails?
0
 
Anurag ThakurTechnical ManagerCommented:
and just one more thing are you returning true whe the format of the phone number is correct
0
 
nightshadzAuthor Commented:
Whoops.  I noticed it's actually not disabled.  I put an alert in my JS function to show me the value passed in from tbPhoneNum.text.  When the page is loaded for the first time, tbPhoneNum.Text is blank which it should be.  When I type something in tbPhoneNum and click btnSave, the value passed to JS is still blank.  It seems tbPhoneNum.Text is passing a blank value rather than what is actually typed in the TextBox.  :confused:
0
 
nightshadzAuthor Commented:
Awesome!  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.