Link to home
Start Free TrialLog in
Avatar of nightshadz
nightshadzFlag for United States of America

asked on

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?
Avatar of Anurag Thakur
Anurag Thakur
Flag of India image

return true from the javascript function
Avatar of nightshadz

ASKER

That will cause a postback and save even invalid entries.
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
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.
what action are you taking - are you disabling the save button if the validation fails?
and just one more thing are you returning true whe the format of the phone number is correct
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:
ASKER CERTIFIED SOLUTION
Avatar of Anurag Thakur
Anurag Thakur
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome!  Thanks!