So I need to make a list of items with delete buttons delete their specific item. I set up an Ajax call and a webmethod in the codebehind, as I've done before in this site, but for some reason it returns the page's entire HTML again, rather than executing the webmethod and returning what I'd like it to return. Frustrated I tried to use a pagemthod instead, but it returns the same result without executing my webmethod at all.
Interestingly I have this working on several other pages already, and basically copy and pasted what I had, but for some reason on this page it doesn't work. Which means I know that it's not an issue with the server or any httpModules in the web config. I've tried the solutions I used before on my site, which were:
form1.Action = Request.RawUrl;
at the top of the Page_Load function in codebehind, because of URL rewriting
PageMethods.set_path("~/Inbox.aspx");
in the javascript for the same reason as above
The below was a proposed solution to go in the web.config, but it just causes the whole server to 500. I don't see how it could help anyway though since pagemethods and ajax work on other pages on my site.
<system.web>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web>
I've stripped the code down to almost nothing to make it function as basically as possible, so I'm certain there are no errors. The code always executes as successful anyway.
Here's the full code, just for context:
HTML/JS:
<form id="form1" runat="server" style="text-align:left">
<asp:ScriptManager runat="server" ID="mailSM" EnablePageMethods="true" EnablePartialRendering="true" ClientIDMode="Static" ></asp:ScriptManager>
<input runat="server" id="maillist" type="hidden" value="" />
<input runat="server" id="inboxhf" type="hidden" value="1" />
<div id="mail-collection" class="main-container">
<a id="back" class="buttons" href="/">back</a><a class="buttons" href="/sendmail">send new mail</a><a id="box" class="buttons" href="/outbox">your sent mail</a>
</div>
<script type="text/javascript">
function DeleteMail(mailID, fromID, toID) {
let pagepath = window.location.pathname.substr(1);
PageMethods.set_path("Mailbox.aspx");
PageMethods.DeleteMailCB(fromID, toID, pagepath, mailID, OnSuccess, OnError);
}
function OnSuccess(response) {
alert(response);
location.reload();
}
function OnError(response) {
alert("e" + response);
//OnSuccess();
}
</script>
</form>
C#:
[WebMethod]
public static void DeleteMail(string fromID, string toID, string pagepath, string mailID)
{
DB.TestForSomething();
//above just does a basic INSERT straight into a test table in the
//database. since nothing is being inserted, I know this webmethod
//isn't getting used at all.
return;
}
Not sure what I should do from here since the solutions that I've found work on the other pages, but not this one. Thanks in advance!