Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4324504
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:08:30+00:00 2026-05-21T09:08:30+00:00

For several days now I’ve been messing around with Ajax calls using different combinations

  • 0

For several days now I’ve been messing around with Ajax calls using different combinations of javascript, ASP controls, and regular controls. I’ve gotten a bit of understanding about what’s going on, but using ASP controls still hides too much of the machinery, and I want to have a deeper understanding. With that aim, can anyone tell me why the following setup doesn’t quite work?

I have a file “Testy.aspx” with the following:

<asp:Content>
  <script type="text/javascript">
  // a standard home-grown Ajax javascript method
  function ajaxfunction() {
    var ajaxObj = getAjaxObj(); // does the usual browser-detection
    if (ajaxObj) {
      ajaxObj.open("GET", "Testy.aspx", true);
      ajaxObj.setRequestHeader("IsAjaxRequest", "true");
      ajaxObj.send();
      ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) {
          document.getElementById("testytext").appendChild(document.createTextNode(ajaxObj.responseText));
        }
      }
    }
  }
  </script>

  ... other unrelated html, ASP controls, etc...

  <input id="testybutton" type="button" value="baroo" onclick="ajaxfunction()" />
  <div id="testytext"></div>

</asp:Content>

Meanwhile, I have a code-behind function “Testy.aspx.vb” with the following:

Partial Public Class Testy
  Inherits System.Web.UI.Page
  Implements System.Web.IHttpHandler

  ...code for an ordinary (non-Ajax) request is in the middle here...

  ' Now I have code for Ajax requests
  Overrides Sub ProcessRequest(ByVal context As HttpContext)
    If context.Request.Headers("IsAjaxRequest") = "true" Then
      context.Response.ContentType = "text/plain"
      context.Response.Write("Hello World!")
    Else
      MyBase.ProcessRequest(context)
    End If
  End Sub

  Overloads ReadOnly Property IsReusable() As Boolean
    Get
      Return False
    End Get
  End Property
End Class

So, I hoped to make my .aspx file do double-duty both as the regular-page request handler as well as the Ajax request handler. However, when I click the button (“baroo”) to generate the Ajax request, the result that ends up written back to the “testytext” div is the raw html for the entire page, as if under normal request conditions. Clearly, my attempt to override the page request by making the code-behind implement IHttpHandler and supplying an “Overrides Sub ProcessRequest” method is not working. The server is still treating the Ajax request as a normal request, and in fact my own “ProcessRequest” method is never even called.

Is it possible to build a page/handler like this? How can I intercept the incoming request from the client and respond accordingly? This is how Ajax works, right? So it must be possible.

Again, I’m deliberately doing this as an excercise to avoid the use of “magic” ASP controls like UpdatePanels, so please don’t advise their use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:08:30+00:00Added an answer on May 21, 2026 at 9:08 am

    Setup a different file that is your generic handler and don’t combine the two.

    Generic Handlers (.ashx) and regular web forms (.aspx) differ in that generic handlers do NOT run all of the normal win form page processing and instead simplify things quite a bit. Generally speaking you don’t want the full page model for this situation, hence the reason they should be different files.

    If you really want to have the methods in your main page that you’ll call via ajax, then look into the “WebMethod” attribute. However, I wouldn’t go this route.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on this for a few days now, and I've found several
I've been using Fiddler for a few days now, extending CustomRules.js with my own
I have been struggling with this for several days now and I ran out
I've been hacking at a problem on and off for several days now that
I've been trying to figure out how to do this for several days now
I now get the ASP.NET Ajax client-side framework failed to load. javascript error in
Several of my ajax applications in the past have used GET request but now
Several times now I've been faced with plans from a team that wants to
I have tried for several days now to get autocomplete working. I have a
The solution for this error has escaped me for several days now, and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.