Archive for July 13th, 2007

Getting Plain Text From An ASP.NET 2.0 Page For Use As An AJAX Data Source

In a follow-up comment to my answer on his AJAX question on Yahoo! Answers, mzanime2000 posed a problem faced by many ASP.NET programming beginners: how to get ASP.NET to return plain text only for use in AJAX.

Wow thanks! Pretty nice well-detailed response. Now I just hope I can get it to work with ASP.NET, I see that you used PHP in your example. One thing I still dont get though, is how Ajax invokes the SQL data when it looks like you used PHP to do the msql_connect part. And PHP is pre-processed too

ASP.NET is based around two output models: HTML and XML. The whole approach assumes you’re either going to spit out a Web page or some XML at the end of the process. Thus, all the controls, all the tutorials … everything is aimed at outputting HTML or XML. But for an AJAX data source such as the type I discussed in my previous blog entry, you need plain text.

The fix is to remove all HTML formatting from the ASPX page, and place our code directly into the ASPX page itself. That will let us call upon Response.ContentType, which will send our database results as text — which is just what our Google Maps API, and all other AJAX applications, want to see.

Read the rest of this entry »