1

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.

codingjoe
  • 707
  • 5
  • 15
  • 32
  • You should do some more googling, adding 'ajax' in your search terms. You may, for example, end-up on http://api.jquery.com/load/ – jbl May 23 '13 at 13:45
  • I am aware of ajax and I am using jquery in a lot of places in my application. However I don't need jquery here or any ajax functionality. I just want to make a MapHandler instead of IFraming a map. So I am more interested in knowing whether I can return html from a generic handler. – codingjoe May 23 '13 at 13:51
  • 1
    I am wondering how you will avoid using ajax to load the html content provided by your handler. Will you be calling the ashx server side ? – jbl May 23 '13 at 14:07
  • You've got a point. I haven't thought about that yet. To start with I just wanted to experiment with returning html, and take it from there... – codingjoe May 23 '13 at 14:10

1 Answers1

5

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;
        }
    }
}
Roar
  • 2,117
  • 4
  • 24
  • 39
Leandro Brito
  • 334
  • 2
  • 13
  • Thanks a lot :) I knew it would be something simple. But nothing came up while googling it. How would it be called from the callers side? A way to call the handler from the markup file. – codingjoe May 23 '13 at 13:59
  • @codingjoe and if you need session state in your handler, don't forget to have it implement marker interface System.Web.SessionState.IRequiresSessionState – jbl May 23 '13 at 14:15
  • I use the generic handler with jquery/ajax because if you want to get the information on C# code (server side) you don't need an ashx. Glad to help. Look this example: http://forums.asp.net/t/1823886.aspx/1 – Leandro Brito May 23 '13 at 18:23
  • @Leandro thanks I have also come the conclusion, that I can use a regular usercontrol to wrap my stuff in. I dont need a ashx generic handler. I have used a generic handler for streaming images out. Thanks for the link and comments. – codingjoe May 23 '13 at 19:50
  • It might be too late, but I think you can find your answer on how tocall it from below link: – InkHeart Aug 12 '16 at 00:18