what replaces #include in .Net?

D

David

As very often is the case a web page has a main, dynamic content page and a
surrounding, more constant "frame" (not html frame!) for stuff like menu,
logo, links etc. In my old ASP web pages I solved this by using #include so
that each .asp page simply started with including this in the top of the
file. Actually it was also ASP code since some of the frame content was
dynamically created from the database.

I can see many possibilities now with .Net to do this but which one would
you suggest?
 
T

Tee

Hi,


There is nothing that really replaces #include, but for your case here and
what you need, the best I think can really replace it is using a placeholder
as a content holder, and code all your content page in web user control.
Then call it out with the following code:

PlaceHolder.Controls.Add(LoadControl"WebUserControl.ascx"))



HTH,
Tee
 
D

David

ok seems everyone agrees so I'll go for webcontrols :)


also I used to have a global function JScript library for small functions
used on almost every .asp page... this was also included. Is this best
solved using a codeback reference on every .aspx page or is there some other
more global method?
 
C

Cowboy \(Gregory A. Beamer\) [MVP]

There are two normal reasons for #INCLUDE in ASP.

1. Code used in various pages
2. UI elements

For pure code, stick it in its own class and call that class. For pure
helper methods, make them static (Shared in VB.NET).

For UI elements and/or UI and code, create a control. The easiest to get up
and running quickly is a web user control, or .ascx file.

In 2.0, you can also put common information into master pages to easily
"chrome" your site (menus, et al).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
D

David

hmm Dimitris I don't agree with you there although I'm pretty new at .Net it
seems to me you are somehow misunderstanding the design... no offence
 
J

John Saunders

David said:
As very often is the case a web page has a main, dynamic content page and a
surrounding, more constant "frame" (not html frame!) for stuff like menu,
logo, links etc. In my old ASP web pages I solved this by using #include so
that each .asp page simply started with including this in the top of the
file. Actually it was also ASP code since some of the frame content was
dynamically created from the database.

I can see many possibilities now with .Net to do this but which one would
you suggest?

User Controls are the closest equivalent to #includes. The nice thing about
them is that they can contain just HTML, or HTML and code. The web designers
can change the HTML with relatively little impact on the code. Just don't
let them change the names of the controls.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top