I’m working with a VB.Net page which calls a web method from JavaScript, this was working upto a week ago and now for some reason is not working. I was wondering if anyone could give me any idea where to look as I am completely lost right now.
Firstly my page generates a list of items that can be clicked, The line that does this is:
TicketHTML = TicketHTML + "<td><img src='../images/delete.png' Class='imgTicketClose' alt='Delete Task' onclick='DeleteTicket(" + row("id").ToString() + ")' /></td></tr>"
I know this is working as when the item is clicked I get a javascript popup so I would assume the problem is not here.
Now my Javascript:
function DeleteTicket(ticketID)
{
var answer = confirm("Do you really want to delete this task?")
if (answer)
{
PageMethods.DeleteTask(ticketID);
window.location.reload()
}
}
I assume the problem is here as the web method never seems to call and the page doesnt seem to reload either, but I dont understand why this would be failing if the javascript displays the confirm dialog.
In the interest of completeness here is my web method though I know this is not being called as I have profiled the database.
<System.Web.Services.WebMethod()>
Public Shared Sub DeleteTask(ticketID As Integer)
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Blueprint").ToString())
Dim cmd As New SqlCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "spDeleteNonTicketItem"
cmd.Parameters.AddWithValue("@ItemID", ticketID)
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
End Sub
So where could I look? Any advice would be greatly appreciated. Thanks
EDIT: Could anything in the web.config file be preventing page methods from executing?
I have just noticed this happening with a completely seperate web method and have checked the integers being passed into the javascript with an alert() and they are all valid
EDIT – I can see you have added the WebMethod attribute.
One thing you can do is add an error handler to your page methods call. You can usually supply method handlers for onsuccess and onError.
For example, you can add the following javascript method:
And then, in your PageMethods call:
Just found a StackOverflow question with an example of this. Note also the effects of CustomError in web.config.
Further Edit.
Have you done a release recently?
You need to make sure that:
1) On the ScriptManager of your page, EnablePageMethods=”true” is set
2) Web.config should have the following lines in the relevant sections: