ASP.Net button call javascript function

I have a javascript function that looks at input on a SSN and then corrects it for the proper dashes. I origincally used this in a traditional ASP page, and it worked fine. Now I want to use it in an ASP.Net page. The user enters a SSN and clicks a button to find the record. It returns the correct data for that number. The numbers are stored in the database with the XXX-XX-XXXX format. So when a user enters one without the dashes, this javascript cleans it up when the user clicks search. How can I get it to run in ASP.Net? I have the javascript in the page, but I'm not sure how to call it properly with the button. The On_Click event runs the search. Do I use it in the OnClientClick event? The button itself is simple:
<asp:Button ID="Find" runat="server" Text="Find User" onClick="Find_Click" onClientClick="form_Validation()"></asp:Button>

The javascript is here:

<script type="text/javascript">
  var reSSN = /^[0-9]{3}\-[0-9]{2}\-[0-9]{4}$/;
  var altSSN = /^\d{9}/;
  var altPattern = /(\d{3}) (\d{2}) )\d{4})/;

  function form_Validation(thisform) {

    with (thisform) {
   
        var SSN = SSN.value;

            if (SSN.length > 0) {
      
            if (altSSN.test(SSN)) {

                  SSN = SSN.replace(altPattern, "$1-$2-$3");
                  SSN.value = SSN;
            }

            if (!reSSN.test(SSN)) {
                  alert("Social Security Number is not correct\nPlease use XXX-XX-XXXX\n");
                  SSN.focus();
                  return false;
            }
      }
      }
      return true;
}
</script>
dodgerfanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brad HoweDevOps ManagerCommented:
Please take a read through the following article.

http://www.techrepublic.com/article/tie-javascript-events-to-aspnet-objects/5031730

Essentially, JS and ASP.net is not the same combination as old HTML/Classic ASP integration. You need to add the script to the form and add the attribute.

butSubmit.Attributes.Add("onClick", "return form_Validation();")

Cheers,
Hades666
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sarabhaiCommented:
why u are not using validation control on the button for Social Security Number.
0
sarabhaiCommented:
just use CompareValidator Control
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.