ASP.NET: Using XMLHTTP With ASP.NET and JavaScript, Server Processing Without PostBacks

Last week I was working on a web interface, Where I wanted to get/post some data from/to the server in XML Format without posting back the page.
Well, XMLHTTP was the best method around with POST method.
Here is the complete sample for using XMLHTTP Post Calls Using JavaScript And ASPX Pages.
Basically, The method can be implemented in the following manner:
For Client:
  1. Create a HTML Page, add the given JavaScript To It.
  2. Add the given HTML Button on the page.
For Server:
  1. Create an ASPX Page.
  2. Remove the HTML, Head and Body Sections, so that it contains only the Code Behind linking information.
  3. In The Page Load Event of this page, Create a StreamReader Object.
  4. Read The Input Stream In The Reader, Load it in XML Document Object.
  5. Process The XML as required.
  6. Send back the XML to the client calling.
Some important points are:
  • Before sending the XML as String to the ASPX Page, replace the < with &lt; and > with &gt; to avoid a Potentially Dangerous Request Error. (The given function is already doing that)
So The basic flow is like:
  • Do the required actions to get the XML Data.
  • Post the XML Data as string to the aspx page.
  • Read the Posted XML Data in the ASPX Page through Input Stream.
  • Do the modifications required in the XML Data after loading it in a XML Document object.
  • Write the XML Data as String back in the Response.
  • Read the data sent back by the ASPX Page by using responseText property in JavaScript.
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.