By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,249 Members | 1,853 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,249 IT Pros & Developers. It's quick & easy.

Confused on CodeBehind Partial Classes in 2.0

P: n/a
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
Jul 11 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
Jul 11 '06 #2

P: n/a
On Tue, 11 Jul 2006 12:39:45 +0300, "Teemu Keiski"
<jo****@aspalliance.comwrote:
>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)

thanks, very helpful.
Peter Kellner
http://peterkellner.net
Jul 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.