Deriving from C# ASPX Pages

  • Thread starter Thread starter Dmitri Shvetsov
  • Start date Start date
D

Dmitri Shvetsov

Hi,

Does anybody know how to create a root class with ASPX page to derive from
this class then? The idea was to create the "root" page with all
evaluations, restrictions, basic interface, etc., then derive a new class
from it.

Maybe URLs, documentation?

Dmitri.
 
Create a class that inherits from Page. Then derive all your pages from
this new class.

BTW, ASP.NET questions are more effectively answered in the
"microsoft.public.dotnet.framework.aspnet" newsgroup.
 
Hi Peter,
Create a class that inherits from Page. Then derive all your pages from
this new class.

Can you say what exactly I should derive? Only class? No ASPX, only a class
where I need to insert all methods that I want to call from the inherited
class?

Is it possible to create something like a "root" aspx page with image, some
permission control etc., then to derive from this class?
BTW, ASP.NET questions are more effectively answered in the
"microsoft.public.dotnet.framework.aspnet" newsgroup.

Hm, thanks a lot! I will run there.

Dmitri.
 
Dmitri,
The way ASP.net codebehind works is that your ASPX is your
presentation. The web page cant be inherited physically but you could
logically inherit the behaviour using the code-behind. Unfortunately the
problem with the VS.net ide is that it presupposes one class codebehind
per ASPX page. So the ide messes up inheritence when youu do something
like this...

1. Create a Base Page with certain fields and layout
2. Create a new ASPX page and the ide creates another page with another
codebehind CS file
3. Change the codebehind files base class from page to your base page...

Everything hunky dory until now, but this is where it breaks...

The new ASPX page has no idea of the layout or the controls in the base
page. And if you add it in the ASPX page its changes the codebehind and
messes things up even more.

Moral of the story is...

User inheritance in the codebehind file
map the new ASPX page's codebehind to the derived codebehind class

Its hard to do visual inheritance like in windows forms
Hope that dint muddle u even more :)
 
Yes, I dont question that you can make it work, but I question VS.net
IDE's handholding that makes something like that difficult to do, all
because it assumes how everyone will work with ASP.net.
Also if you look at the controls example closely, There is no visual
inheritance. Its the codebehinds that do the work of rendering.
 
Is it possible to create something like a "root" aspx page with image,
some
permission control etc., then to derive from this class?

I tend to put only permission control code in a base C# class, specifically
in the Initialize method, so that derived classes must call base.Initialize
in their Initialize methods.

Any common HTML (like header and footer, eg start and end of the outer TABLE
of every page) goes into ascx controls, then I include these controls
explicitly in the right spot on individual aspx pages. I leave HTML, HEAD,
and FORM tags explicit in each .aspx. Barbaric, I know, but generating this
stuff in the codebehind, as in that codeproject submission, will not
lengthen your life, and it may get you into fights with Visual Studio
designer.

Brad Williams
 
Thanks Brad,

That's a good advice.

Dmitri.

Brad Williams said:
I tend to put only permission control code in a base C# class, specifically
in the Initialize method, so that derived classes must call base.Initialize
in their Initialize methods.

Any common HTML (like header and footer, eg start and end of the outer TABLE
of every page) goes into ascx controls, then I include these controls
explicitly in the right spot on individual aspx pages. I leave HTML, HEAD,
and FORM tags explicit in each .aspx. Barbaric, I know, but generating this
stuff in the codebehind, as in that codeproject submission, will not
lengthen your life, and it may get you into fights with Visual Studio
designer.

Brad Williams
 
Hi again,

Yes, that's very bad, but you're absolutely right. It would be excellent IDE
if we could use the visual inheritance. Maybe we need to play with it a
little bit longer or just wait for a newer version of IDE... in a few years.

Dmitri.
 
There is already a Global class that you could use. The advantage of
ASP.Net is you don't have to build infrastructure so building a base
class may perhaps be not required if you give it a rethink.

with regards,


J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
 
Back
Top