<p>I'm about to start a fairly Ajax heavy feature in my company's application. What I need to do is make an Ajax callback every few minutes a user has been on the page. </p>

<ul>
<li>I don't need to do any DOM updates before, after, or during the callbacks. </li>
<li>I don't need any information from the page, just from a site cookie which should always be sent with requests anyway, and an ID value.</li>
</ul>

<p>What I'm curious to find out, is if there is any clean and simple way to make a JavaScript Ajax callback to an ASP.NET page without posting back the rest of the information on the page. I'd like to not have to do this if it is possible.</p>

<p>I really just want to be able to call a single method on the page, nothing else.</p>

<p>Also, I'm restricted to ASP.NET 2.0 so I can't use any of the new 3.5 framework ASP AJAX features, although I can use the ASP AJAX extensions for the 2.0 framework.</p>

<p><strong>UPDATE</strong><br>
I've decided to accept <a href="https://stackoverflow.com/questions/27258/aspnet-javascript-callbacks-without-full-postbacks#27270">DanP</a>'s answer as it seems to be exactly what I'm looking for. Our site already uses jQuery for some things so I'll probably use jQuery for making requests since in my experience it seems to perform much better than ASP's AJAX framework does. </p>

<p>What do you think would be the best method of transferring data to the IHttpHandler? Should I add variables to the query string or POST the data I need to send?</p>

<p>The only thing I think I have to send is a single ID, but I can't decide what the best method is to send the ID and have the IHttpHandler handle it. I'd like to come up with a solution that would prevent a person with basic computer skills from accidentally or intentionally accessing the page directly or repeating requests. Is this possible?</p>

[{'answer_id': 27264, 'author': 'abigblackman', 'author_id': 2279, 'author_profile': 'https://Stackoverflow.com/users/2279', 'pm_score': 2, 'selected': False, 'text': '<p>You are not just restricted to ASP.NET AJAX but can use any 3rd party library like jQuery, YUI etc to do the same thing. You can then just make a request to a blank page on your site which should return the headers that contain the cookies. </p>\n'}, {'answer_id': 27270, 'author': 'Daniel Pollard', 'author_id': 2758, 'author_profile': 'https://Stackoverflow.com/users/2758', 'pm_score': 4, 'selected': True, 'text': '<p>If you don\'t want to create a blank page, you could call a IHttpHandler (ashx) file:</p>\n\n<pre><code>public class RSSHandler : IHttpHandler\n    {\n        public void ProcessRequest (HttpContext context)\n        {   \n            context.Response.ContentType = "text/xml";\n\n            string sXml = BuildXMLString(); //not showing this function, \n            //but it creates the XML string\n            context.Response.Write( sXml );\n        }\n\n        public bool IsReusable\n        {\n            get { return true; }\n        }\n\n    }\n</code></pre>\n'}, {'answer_id': 27275, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': -1, 'selected': False, 'text': '<p>You can also use WebMethods which are built into the asp.net ajax library. You simply create a static method on the page\'s codebehind and call that from your Ajax.</p>\n<p>There\'s a pretty basic example of how to do it <a href="https://web.archive.org/web/20200803212711/http://geekswithblogs.net/frankw/archive/2008/03/13/asp.net-ajax-callbacks-to-web-methods-in-aspx-pages.aspx" rel="nofollow noreferrer">here</a></p>\n'}, {'answer_id': 27278, 'author': 'Jim', 'author_id': 1208, 'author_profile': 'https://Stackoverflow.com/users/1208', 'pm_score': -1, 'selected': False, 'text': "<p>You should use a web service (.asmx).  With Microsoft's ASP.NET AJAX you can even auto-generate the stubs.</p>\n"}, {'answer_id': 27295, 'author': 'Ricky', 'author_id': 653, 'author_profile': 'https://Stackoverflow.com/users/653', 'pm_score': 2, 'selected': False, 'text': '<p>You should use ASP.Net Callbacks which were introduced in Asp.Net 2.0. Here is an article that should get you set to go:</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms178208.aspx" rel="nofollow noreferrer">Implementing Client Callbacks Programmatically Without Postbacks in ASP.NET Web Pages</a></p>\n\n<p>Edit: Also look at this:\n<a href="http://aspalliance.com/1537" rel="nofollow noreferrer">ICallback &amp; JSON Based JavaScript Serialization</a></p>\n'}, {'answer_id': 27312, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 2, 'selected': False, 'text': '<p>My vote is with the HTTPHandler suggestion as well. I utilize this often. Because it does not invoke an instance of the page class, it is very lightweight. </p>\n\n<p>All of the ASP.NET AJAX framework tricks actually instantiate and create the entire page again on the backend per call, so they are huge resource hogs.</p>\n\n<p>Hence, my typical style of XmlHttpRequest back to a HttpHandler.</p>\n'}, {'answer_id': 27340, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 2, 'selected': False, 'text': "<blockquote>\n  <p>What do you think would be the best method of transferring data to the IHttpHandler? Should I added variables to the query string or POST the data I need to send? The only thing I think I have to send is a single ID, but I can't decide what the best method is to send the ID and have the IHttpHandler handle it. I'd like to come up with a solution that would prevent a person with basic computer skills from accidentally or intentionally accessing the page directly</p>\n</blockquote>\n\n<p>Considering the callback is buried in the client code, it would take someone with equal determination to get either the querystring or the POST request. IE, if they have firebug, your equally screwed.</p>\n\n<p>So, in that case, do whatever is easiest to you (Hint: I'd just use the querystring).</p>\n\n<p>To handle repeating requests/direct access, I'd generate a key that is sent with each request. Perhaps a hash of the current time (Fuzzy, I'd go down to minutes, but not seconds due to network latency) + the client IP.</p>\n\n<p>Then in the HTTPHandler, perform the same hash, and only run if they match.</p>\n"}, {'answer_id': 28105, 'author': 'David Basarab', 'author_id': 2469, 'author_profile': 'https://Stackoverflow.com/users/2469', 'pm_score': 1, 'selected': False, 'text': '<p>Since you are using only ASP.NET 2.0 I would recommend <a href="http://www.ajaxpro.info/" rel="nofollow noreferrer">AjaxPro</a> will which create the .ashx file.  All you have to do is to pull the AjaxPro.dll into your web site.  I developed an entire application with <a href="http://www.ajaxpro.info/" rel="nofollow noreferrer">AjaxPro</a> and found it worked very well.  It uses serialization to pass objects back and forth.</p>\n\n<p>This is just a sample on how to simply use it.</p>\n\n<pre><code>namespace MyDemo\n{\n  public class Default\n  {\n    protected void Page_Load(object sender, EventArgs e)\n    {\n      AjaxPro.Utility.RegisterTypeForAjax(typeof(Default));\n    }\n\n    [AjaxPro.AjaxMethod]\n    public DateTime GetServerTime()\n    {\n      return DateTime.Now;\n    }\n  }\n}\n</code></pre>\n\n<p>To call it via JavaScript it is as simple as </p>\n\n<pre><code>function getServerTime()\n{\n  MyDemo._Default.GetServerTime(getServerTime_callback);  // asynchronous call\n}\n\n// This method will be called after the method has been executed\n// and the result has been sent to the client.\n\nfunction getServerTime_callback(res)\n{\n  alert(res.value);\n}\n</code></pre>\n\n<p><strong>EDIT</strong></p>\n\n<p>You also have to add </p>\n\n<p>\n      \n</p>\n\n<p>To the config.  AjaxPro also works well side by side with APS.NET Ajax and you can pass C# objects from Client to Sever if the class is marked as [Serializable]</p>\n'}, {'answer_id': 1958357, 'author': 'David Robbins', 'author_id': 19799, 'author_profile': 'https://Stackoverflow.com/users/19799', 'pm_score': 1, 'selected': False, 'text': '<p>Just to offer a different perspective, you could also use a PageMethod on your main page.  Dave Ward has a nice post that <a href="http://encosia.com/2008/06/26/use-jquery-and-aspnet-ajax-to-build-a-client-side-repeater/" rel="nofollow noreferrer">illustrates</a> this.  Essentially you use jQuery ajax post to call the method, as illustrated in Dave\'s post:</p>\n\n<pre><code>$.ajax({\n    type: "POST",\n    url: "Default.aspx/GetFeedburnerItems",\n    // Pass the "Count" parameter, via JSON object.\n    data: "{\'Count\':\'7\'}",\n    contentType: "application/json; charset=utf-8",\n    dataType: "json",\n    success: function(msg) {\n      BuildTable(msg.d);\n    }\n  });\n</code></pre>\n\n<p>No need for Asp.Net Ajax extensions at all.</p>\n'}]
['https://Stackoverflow.com/questions/27258', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/392/']