views:

44

answers:

2

How can I used include files (as used in classic asp) in asp.net 3.5 framework?

+1  A: 

You should use User Controls instead.

To share server-side code between pages, you should add C# classes to the App_Code folder.

SLaks
stupid question but why did MS make this so more complicated?
Troy
Because simple include files are poor design.
SLaks
Complicated... my memory of classic ASP was that of nightmarish maintenance. In my mind the inheritance model of ASP.Net is a blessing compared with the brittleness of page includes.
Josh
Sometimes includes are a simple fact of life. For example, if you're in a organization where designers are doing the layout of everything, they're accustomed to using include files. Static or dynamic, Linux or Windows, they'll use includes. As a programmer, you could certainly turn all of them into user controls in ASP.NET, but often (at least where I work), that means designers are instantly scared to touch them and all maintenance now goes through you. At any rate, that has just been my experience.
Anthony Pegram
(Goes with above) Keep in mind, this refers to repeated content that's more static in nature, such as headers, navigation, footers, etc. Obviously, reusable pieces that are more dynamic should be controls.
Anthony Pegram
This is interesting. I never realized include files was not available in .Net
user279521
A: 

These were used in classic ASP to simulate a lack of any inheritance model, or composability. In ASP.Net you can use inheritance to create common functionality. Master Pages for common layout, and user controls for composability.

Inheritance will work in all three of these situations as well.

MyPage: BasePage

MyControl: BaseControl

MyMasterPage: BaseMasterPage

You have a lot of options with ASP.Net because it is built on top of an Object Oriented framework.

Josh