0

I need to call a function when an Ajax page method function returns success and without button click as protected sub. I couldn't include the ClientScript directly in the method or in shared function and the Method doesn't allow calling Public Sub UpdateText() without Shared ... any ideas?

'''' Method for Ajax with SQL and other functions
'''' ----------------------------------------------------------
<WebMethod()> _
Public Shared Function SendOrder(ByVal fulldata As String, 
_ByVal id As Integer) As String

            Try

            UpdateText()
            Return "Success"

        Catch ex As Exception
            Return "failure"
        End Try

End Function

And here is the function I need to call

'''' Function to call only on success
'''' ----------------------------------------------------------
Public Sub UpdateText()

    Dim jsUpdate As String
    Dim cstype As Type
    Dim cs As ClientScriptManager = Page.ClientScript
    Dim jsUpdateTxt As String = "<script language='javascript'>...</script>"
    ClientScript.RegisterStartupScript(cstype, jsUpdate, jsUpdateTxt)

End Sub
hsobhy
  • 1,493
  • 2
  • 21
  • 35

1 Answers1

0

Page method calls have to be static.They cannot interact with the instance properties and methods of your Page class, because a page method call creates no instance of the Page or any of its controls.

after return either Success or failure, you can coding ajax methods in the client side like that

PageMethods.SendOrder(fulldata,id,OnRequestComplete, OnError);

 function OnRequestComplete(result) {
        //ToDo
      }    

  function OnError(result) {
        //ToDo
      } 
bashkan
  • 464
  • 1
  • 5
  • 14