Confused on CodeBehind Partial Classes in 2.0

P

PeterKellner

I'm trying to understand how asp.net 2.0 ties together the codebehind.
I've made a simple page, turned debug on so the *0.cs,*1.cs,*2.cs
files don't get erased.

My first point of confusion is that the *1.cs file is declared like
this:

public partial class _Default : System.Web.UI.Page
{...

And the *0.cs file is declared like this:

public partial class _Default :
System.Web.SessionState.IRequiresSessionState {

I'm thinking they are both partial classes of the same thing yet they
derive from different base classes. I thought partial classes had to
derive from the same base class?

My second point of confusion is about the page class itself. I'm
assuming there is only one page class per aspx page, and in my
example, it's name is default_aspx.

public class default_aspx : global::_Default, System.Web.IHttpHandler
{

This to me says that default_aspx (the one page class that controls
the page) derives from _Default and implements the interface
IHttpHandler. My confusion is that if _Default already implements
System.Web.UI.Page, why does default_aspx have to implement it also?

Just trying to understand. Thanks for reading.



Peter Kellner
http://peterkellner.net
 
T

Teemu Keiski

Hi,

comments inline
public partial class _Default : System.Web.UI.Page
{...

And the *0.cs file is declared like this:

public partial class _Default :
System.Web.SessionState.IRequiresSessionState {

I'm thinking they are both partial classes of the same thing yet they
derive from different base classes. I thought partial classes had to
derive from the same base class?

IRequiresSessionState is an interface telling that the Page uses session
state. Basically they still have the same base class which is
System.Web.UI.Page. It is already assumed since *1.cs already declares the
base class and therefore declaring it in the auto-generated class is not
needed. (*1.cs corresponds to your code-behind class, *0 is the
autogenerated class which also declares members etc and it's based on *1.cs)
My second point of confusion is about the page class itself. I'm
assuming there is only one page class per aspx page, and in my
example, it's name is default_aspx.

public class default_aspx : global::_Default, System.Web.IHttpHandler
{

This to me says that default_aspx (the one page class that controls
the page) derives from _Default and implements the interface
IHttpHandler. My confusion is that if _Default already implements
System.Web.UI.Page, why does default_aspx have to implement it also?

It is just reimplementation of the interface in subclass. Basically, I'd see
it to be a trick to ensure the subclass is the class "used" when request is
processed while keeping extensibility in mind. IHttpHandler.ProcessRequest
is re-implemented in default_aspx, but it calls base.ProcessRequest (it's
added in case it's needed to extend when just overriding is simple)
 
P

PeterKellner

Hi,

comments inline


IRequiresSessionState is an interface telling that the Page uses session
state. Basically they still have the same base class which is
System.Web.UI.Page. It is already assumed since *1.cs already declares the
base class and therefore declaring it in the auto-generated class is not
needed. (*1.cs corresponds to your code-behind class, *0 is the
autogenerated class which also declares members etc and it's based on *1.cs)


It is just reimplementation of the interface in subclass. Basically, I'd see
it to be a trick to ensure the subclass is the class "used" when request is
processed while keeping extensibility in mind. IHttpHandler.ProcessRequest
is re-implemented in default_aspx, but it calls base.ProcessRequest (it's
added in case it's needed to extend when just overriding is simple)


thanks, very helpful.
Peter Kellner
http://peterkellner.net
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top