开发者

How can i return the result of an HttpHandler and set it to the text property of a label in asp

I would like to be able to return the text generated from an httphandler and insert it into my web page during an onload event. There are examples that show how to return an image by setting the 开发者_JAVA百科image source to the path of the handler. But how do you do this for just text as in the "hello world" basic template. I would like the text value of a label on my page to be set to "hello world", preferably withour using javascript.


You can try using the session variable in your HttpHandler. By default you won't have access to the Session object.

You have include the following library:

using System.Web.SessionState;

After that the class should inherit IRequiresSessionState.

public class NewHandler : IHttpHandler, IRequiresSessionState

Later you can access the value of this Session variable from your code behind.


IHttpHandler.ProcessRequest method takes a parameter of type HttpContext. This class has a property Items, which is a name value pair. You can add your string to this Items collection and later refer to it where ever HttpContext is available. Thing to keep in mind is that the Items collection is per request, and does not persist across request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜