Take the 2-minute tour ×

Im struggling to get a web method to work in VB. The javascript gets called but never seems to call the web method. I am running in debug mode and get no errors.

Here is the code:

   Public Shared Sub PasteEvent(EventID As Integer, 
                                startDate As DateTime, 
                                endDate as DateTime, 
                                newStart As DateTime)

      ' work out the diff between start and end
      Dim difference As long = DateDiff(DateInterval.Minute,startDate,endDate)

      ' pasteStart  + minutes from the event start
      ' this is because we can only paste on the hour, but events may have started after the hour
      ' ie 10:15

      ' new end = pastestart + diff
      Dim newEnd As DateTime = newStart.AddMinutes(convert.ToDouble(difference))

      ' call database 
      Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Blueprint").ToString())

      Dim cmd As New SqlCommand
      cmd.CommandType = CommandType.StoredProcedure
      cmd.CommandText = "spOPSCopyEvent"

      cmd.Parameters.AddWithValue("@EventID", EventID)
      cmd.Parameters.AddWithValue("@StartDate", newStart)
      cmd.Parameters.AddWithValue("@EndDate", newEnd)

      cmd.Connection = conn




   End sub

The javascript that calls it:


      function eventCopy(eventID, start, end)
         // grab the event id and store it in a hidden text box

      function eventPaste(eventStart)
         // Call a web method, passing the eventID and the new start time
         var eventID = $("#ctl00_MainContent_hidCopyEventID").val;
         var startDate = $("#ctl00_MainContent_hidCopyStart").val;
         var endDate = $("#ctl00_MainContent_hidCopyEnd").val;

         PageMethods.PasteEvent(eventID, startDate, endDate, eventstart)


So far I have :

Updated my script manager in the master page to have enablePageMethods="true"

Tried adding Imports System.Web.Services

Moved the javascript into the body rather than the head

share|improve this question
Can it be the missing "static" modifier? –  Kemal Taşkın Feb 12 '12 at 12:50
VB wont allow me to declare the method as static, I've used code similar to this before and it works as a web method –  Purplegoldfish Feb 12 '12 at 13:28
add comment

2 Answers

up vote 2 down vote accepted

The problem is that you are missing exception handling mechanism to see what error did you get .

  1. Put try and catch in javascript and vb code and print the error.

  2. Use the sniffer like Fidler to see what you are sending .

  3. Try to print trace messages in web services using Trace.Log and you can see them after running DebugView and see where you are falling

share|improve this answer
I added try / catch and am catching no errors, i also alerted out the params im passing and they appear to be correct. –  Purplegoldfish Feb 12 '12 at 13:29
Added item 3. What did you saw in Fiddler ? Put the alert after PageMethods.PasteEvent(eventID, startDate, endDate, eventstart) and see if it happens. –  Gregory Nozik Feb 12 '12 at 16:10
Good advice. Fiddler led to me solving my (presumably unrelated) problem. –  user12861 Jul 22 '13 at 18:44
add comment

When using this line:


I should have put:

var eventID = $("#ctl00_MainContent_hidCopyEventID").val(); 

Accepting Gregorys answer as fiddler was the most helpfull in diagnosing the issue.

share|improve this answer
add comment

Your Answer


