How to programatically load control in HTTPHandler ?

A

Alex Nitulescu

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
 
A

Aquila Deus

Alex said:
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.
 
W

Willie Ferguson

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/<[email protected]>

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top