Search code examples
c#asp.netgeneric-handler

Using of ashx to populate div with html


Is it possible to use a generic handler (*.ashx) to return html, which I can use within a div tag?

Something like

<div id="foo"> [call my generic handler which returns some html to be used within this div ] </div>

In this case it is not an image, but just HTML.

Haven't found anything while googling.


Solution

  • Yes, you can return something like that:

    public class CustomFormHandler : IHttpHandler {
        public void ProcessRequest (HttpContext context) {
    
            context.Response.ContentType = "text/html";
            context.Response.Write("<p>my html</p>");
        }
        public bool IsReusable {
            get {
                return false;
            }
        }
    }