471,066 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

How to programatically load control in HTTPHandler ?

Hi. I have a web.config which says that all files with the "axd" extension
should by a special handler.

The handler writes some stats to the "axd" page.

Public Class WhosOnHandler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext)
Implements System.Web.IHttpHandler.ProcessRequest
............
context.Response.Write("<table border=1 cellpadding=4 bgcolor=orange>")
context.Response.Write("<tr><td colspan=4 align=center>")
...........
Public ReadOnly Property IsReusable() As Boolean Implements
System.Web.IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class

Note that there *is no* axd aspx page in my project ! Whenever a user
presses on a button named "Stats", the code executes
Response.Redirect("TestForm2.aspx") and the handler detects a call to an AXD
file and takes care of the rest, as above.

My problem is that this axd file looks pretty plain, only with
"context.Response.Write". I have some custom controls which I would like to
load to make this page look consistent with the other pages on this website.

So the question is: how do I programatically load my controls in this
situation? I only have the 'Context' object and I need to somehow get to the
'Page' object to be able to say Page.Controls.Add. In other words, how do I
obtain an instance of this page ?

Thank you.
Alex
Nov 19 '05 #1
2 2420
Alex Nitulescu wrote:
Hi. I have a web.config which says that all files with the "axd" extension should by a special handler.

The handler writes some stats to the "axd" page.

Public Class WhosOnHandler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext)
Implements System.Web.IHttpHandler.ProcessRequest
...........
context.Response.Write("<table border=1 cellpadding=4 bgcolor=orange>") context.Response.Write("<tr><td colspan=4 align=center>")
..........
Public ReadOnly Property IsReusable() As Boolean Implements
System.Web.IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class

Note that there *is no* axd aspx page in my project ! Whenever a user presses on a button named "Stats", the code executes
Response.Redirect("TestForm2.aspx") and the handler detects a call to an AXD file and takes care of the rest, as above.

My problem is that this axd file looks pretty plain, only with
"context.Response.Write". I have some custom controls which I would like to load to make this page look consistent with the other pages on this website.
So the question is: how do I programatically load my controls in this situation? I only have the 'Context' object and I need to somehow get to the 'Page' object to be able to say Page.Controls.Add. In other words, how do I obtain an instance of this page ?


If you want Page, then just use ordinary .aspx. I think the http
handler is completely useless since its URL has to end with the ext
".axd", and you could just replace it with a Page with diffenrent
content-type.

It's not easy to load a Page by yourself, because there are many issues
that ASP.NET has to deal with, such as event dispatching, postback, etc.

Nov 19 '05 #2
Alex,

You can take a look at PageParser.GetCompiledPageInstance which takes the path to the aspx you need to load and return an IHTTPhandler. Call ProcessRequest to execute the aspx page.

Willie

nntp://news.microsoft.com/microsoft.public.dotnet.framework.aspnet/<et**************@tk2msftngp13.phx.gbl>

Hi. I have a web.config which says that all files with the "axd" extension
should by a special handler.

The handler writes some stats to the "axd" page.

Public Class WhosOnHandler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext)
Implements System.Web.IHttpHandler.ProcessRequest
...........
context.Response.Write("<table border=1 cellpadding=4 bgcolor=orange>")
context.Response.Write("<tr><td colspan=4 align=center>")
..........
Public ReadOnly Property IsReusable() As Boolean Implements
System.Web.IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class

Note that there *is no* axd aspx page in my project ! Whenever a user
presses on a button named "Stats", the code executes
Response.Redirect("TestForm2.aspx") and the handler detects a call to an AXD
file and takes care of the rest, as above.

My problem is that this axd file looks pretty plain, only with
"context.Response.Write". I have some custom controls which I would like to
load to make this page look consistent with the other pages on this website.

So the question is: how do I programatically load my controls in this
situation? I only have the 'Context' object and I need to somehow get to the
'Page' object to be able to say Page.Controls.Add. In other words, how do I
obtain an instance of this page ?

Thank you.
Alex


[microsoft.public.dotnet.framework.aspnet]
Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Andrea Williams | last post: by
2 posts views Thread by P. Gruenhagen | last post: by
5 posts views Thread by Author | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.