Ramunas Ramunas - 1 year ago 119
Ajax Question

asp.net javascript ajax error: not found

Trying to send ajax message fails with message:

enter image description here

My simple aspx page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewer.aspx.cs" Inherits="MyProject.AspNetForms.ReportViewer" %>
<script type ="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type ="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function CleanUpSession() {
type: "POST",
url: "ReportViewer.aspx/CleanUp",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{}",
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
success: function (result) {
alert("We returned: " + result);

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<button OnClick="CleanUpSession();">test</button>

cs code:

public partial class ReportViewer : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
public static string CleanUp()
return "My message";


If url changed "ReportViewer.aspx/CleanUp" to "~/AspNetForms/ReportViewer.aspx/CleanUp" then i catch exception

"The file '/AspNetForms/~/AspNetForms/ReportViewer.aspx' does not exist."

Answer Source

Solved my problem. Just used asp:button instead of simple button and ajax

<body onbeforeunload="CleanUpSession();">
<script type="text/javascript">
function CleanUpSession() {
    var item = document.getElementById('<%=ButtonCleanUp.ClientID%>');
    if (item != null)
<form id="form1" runat="server">
<asp:Button ID="ButtonCleanUp" OnClick="CleanUp_Click" Text="Button Text" runat="server"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download