• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

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?
0
nightshadz
Asked:
nightshadz
  • 5
  • 4
1 Solution
 
Anurag ThakurCommented:
return true from the javascript function
0
 
nightshadzAuthor Commented:
That will cause a postback and save even invalid entries.
0
 
Anurag ThakurCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 ThakurCommented:
what action are you taking - are you disabling the save button if the validation fails?
0
 
Anurag ThakurCommented:
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
 
Anurag ThakurCommented:
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
 
nightshadzAuthor Commented:
Awesome!  Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now