0

I am trying to create a search result page with asp.net and jQuery. It has to work in an AJAX manner. What I want is that I send the page number to server via an AJAX call and the server can return an html block so that I can attach this html block to an area in the page in the callback after the AJAX call.

But I don't know how to assemble the html block on the server side. Is there a good way or some kind of engine to achieve this ? Or should I just hard-code it like:

<table><tr><td>My result</td></tr> </table>

and return this text to client?

2 Answers 2

2

There are multiple ways of doing this - you have touched on one:

  1. Return the markup directly and add it.
  2. Return JSON, parse it using standard JavaScript methods into JS objects and:

    2.1 Generate markup in JavaScript and add it.

    2.2 Find the values in the objects and put them in the HTML.

    2.2 Use a client side template library and bind the objects.

Sign up to request clarification or add additional context in comments.

Comments

1

Here is one way to create html block on the server side.

var stringWriter = new StringWriter();
using (var writer = new HtmlTextWriter(stringWriter))
{
    writer.RenderBeginTag(HtmlTextWriterTag.Table);
    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    writer.Write("My result");
    writer.RenderEndTag();
    writer.RenderEndTag();
    writer.RenderEndTag();
}
var result = stringWriter.ToString();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.