Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Fri, 3 Jul 2009 02:20:53 -0700 (PDT),    group: microsoft.public.dotnet.framework.aspnet        back       


Custom PageHandler ???   
Hi,

I have 2 pages: IntPage.aspx and StringPage.aspx with the classes
declared in their respective code behind files.
Both pages are declared in the root folder and work fine

Then I have a CustomPageHandlerFactory class (declared in the App_Code
folder):

  public class MyPageHandlerFactory : PageHandlerFactory
  {
    public override IHttpHandler GetHandler(HttpContext context,
string requestType, string virtualPath, string path)
    {
      IHttpHandler myhandler = null;

      if (some boolean condition)
          myhandler = new IntPage();
      else
          myhandler = new StringPage();
      return myhandler;
    }
  } // class MyPageHandlerFactory

But I get a compiler error on IntPage and StringPage -->
"The type or namespace name 'IntPage' could not be found"
"The type or namespace name 'StringPage' could not be found"

It seems to me that, from a page class you can use any class declared
in the App_Code folder but not the other way around.

How can this be solved ?

thx
Chris
date: Fri, 3 Jul 2009 02:20:53 -0700 (PDT)   author:   Chris

Re: Custom PageHandler ???   
the pages are compiled separately into their own dll(s), so they are not 
known when the appcode is compiled. you need to do this lookup at runtime:

var type = BuildManager.GetCompiledPageType(pagePath);
var myhandler = Activator.CreateInstance(type) as IHttpHandler;

-- bruce (sqlwork.com)


Chris wrote:
> Hi,
> 
> I have 2 pages: IntPage.aspx and StringPage.aspx with the classes
> declared in their respective code behind files.
> Both pages are declared in the root folder and work fine
> 
> Then I have a CustomPageHandlerFactory class (declared in the App_Code
> folder):
> 
>   public class MyPageHandlerFactory : PageHandlerFactory
>   {
>     public override IHttpHandler GetHandler(HttpContext context,
> string requestType, string virtualPath, string path)
>     {
>       IHttpHandler myhandler = null;
> 
>       if (some boolean condition)
>           myhandler = new IntPage();
>       else
>           myhandler = new StringPage();
>       return myhandler;
>     }
>   } // class MyPageHandlerFactory
> 
> But I get a compiler error on IntPage and StringPage -->
> "The type or namespace name 'IntPage' could not be found"
> "The type or namespace name 'StringPage' could not be found"
> 
> It seems to me that, from a page class you can use any class declared
> in the App_Code folder but not the other way around.
> 
> How can this be solved ?
> 
> thx
> Chris
date: Fri, 03 Jul 2009 15:58:33 -0700   author:   bruce barker

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us