1

Here is my desired flow:

  1. A static web page (html) uses XHR calls to an ASP.NET page
  2. The .NET page retrieves information from a remote server using web services
  3. The .NET page returns an HTML "snippet" that is inserted into the static HTML page

I'm getting hung up on how to deal with the HTML snippet generation on the .NET (2.0) page. I've thought about something like this in a generic .ashx page:

public void ProcessRequest (HttpContext context)
{
  context.Response.Write("<ul>");
  //assume "people" is a list of data coming from the external web service
  foreach (string person in people)
  {
    context.Response.Write("<li>" + person + "</li>");
  }
  context.Response.Write("</ul>");
}

It just seems a big "ugly". Has anyone done this another - and possibly more efficient/elegant - way? Any help would be appreciated.

JayTee
  • 2,776
  • 2
  • 24
  • 27

1 Answers1

1

Returning html for this task is a bit weird, IMO. In most times I prefer the following way. Open your web service to public or add a wrapper to it and just use it directly from js of your static page. The service should return json (preferable) or xml data. On the client side format (print in html as you want) received data using js in callback to the XHR and inject anywhere you want.
But also I want to cast YAGNI on this task - if it'll be used only several times and in a few pages, use the most fastest way to implement it. But if you are building some RIA application I recommend you to check ExtJS javascript library.

Edit 26/02:
If you can't use ASP.NET MVC but wanna to use some good framework instead of "Response.Write" stuff please check OpenRasta. It's one of my favorite web frameworks. It works fine on .Net 2.0 and it's very flexible and powerful. And also it has a great community.

zihotki
  • 5,201
  • 22
  • 26
  • With .NET MVC, you can return an HTML fragment and it works pretty well. Unfortunately, I'm stuck with .NET 2 which doesn't support .NET MVC. I'm looking into using JS more extensively than returning straight HTML. – JayTee Feb 25 '10 at 18:02