title: Calling VB.NET WebMethod Function from Javascript
body: <p>I have a VB.NET function which looks like this:</p>
  
  <pre><code>&lt;WebMethod()&gt; _
  Public Shared Function AuthenticateUser(ByVal UserInfo As String, ByVal Password As String) As Boolean
      Dim UserName As String
  
      'Just in case
      AuthenticateUser = False
  
      'Extract the user name from the user info cookie string
      UserName = Globals.GetValueFromVBCookie("UserName", UserInfo)
  
      'Now validate the user
      If Globals.ValidateActiveDirectoryLogin("Backoffice", UserName, Password) Then
          AuthenticateUser = True
      End If
  
  End Function
  </code></pre>
  
  <p>I'm trying to call it from javascript like this:</p>
  
  <pre><code>function DeleteBatchJS()
  {if (confirm("Delete the ENTIRE batch and all of its contents? ALL work will be lost."))
       var authenticated = PageMethods.AuthenticateUser(get_cookie("UserInfo"), prompt("Please enter your password"))
       if (authenticated == true)
             {{var completed = PageMethods.DeleteBatchJSWM(get_cookie("UserInfo"));
              window.location = "BatchOperations.aspx";
              alert("Batch Deleted.");}}}
  </code></pre>
  
  <p>It calls the function, but won't return a value. When walking through the code, my VB function does fire (it will return true so long as the correct password is typed in), but the javascript 'authenticated' value remains 'undefined'. It's like you can't return values from VB functions to javascript.</p>
  
  <p>I also tried</p>
  
  <pre><code>if PageMethods.AuthenticateUser("UserName", "Password")
     {
       //Stuff
     }
  </code></pre>
  
  <p>But still no luck.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks,</p>
  
  <p>Jason</p>