How to programatically load control in HTTPHandler ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Willie Ferguson (willie.ferguson_at_gmail.com)
Date: 02/03/05


To: microsoft.public.dotnet.framework.aspnet
Date: Wed, 02 Feb 2005 22:25:36 -0800


 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/>

  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]



Relevant Pages