Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include File Equivalent in ASP.NET

Status
Not open for further replies.

starbuckinfinity

Programmer
Jan 31, 2005
8
US
hi. In classic ASP, include files were used for content that would allow you to store content in one file that could simply be "included" in other files that needed the same content. An example would be navigation bars, shared components, etc. I know there are these "server controls" in ASP.NET which are supposed to be similar to include files, but what about files which hold just mainly content things and components that are not functional? Is there anything in ASP.NET that does the equivalent without being for the purpose of building functional components? Or do you just have to put the same code on every page in ASP.NET? With classic ASP, whenever a change needed to be made to, say, a navigation, it was so easy just to open one file and do it in that file. Now, with ASP.NET, if you have to make a change, you would have to open every file that common component was on and make the change if there is no equivalent. Will someone please help me out on this? Thank you.

by the way, I am using VB.NET.
 
The way I do it is by using Inheritance. Basically I have a class (which inherits System.Web.UI.Page) and then all of my pages inherit my class rather than System.Web.UI.Page. This means that if I make any changes to my class, they are automatically reflected in every page!

For more info on how to do this, read the following article (it's in C# but i've converted it to VB so can always give you a few pointers):




----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
thanks for this reply. by the way, excuse my ignorance if this is a dumb question, but is this similar to interface?
 
Not as far as I know.

My understanding of the two words are that an interface is the actual web page you create for them (otherwise known as a Graphical User Interface) and that Inheritance means that it "belongs" to another object (i.e. all my pages belong to my "PageBase" class and therefore when I make a change to this class, all my pages change as well).

Hope this helps.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Hi,
You can build a control and include it just as you would in the old include days. Just build your Page to include, name it with the .ASCX extension (BTW this can be a full fledged ASPX page). Then in your page that is calling it you need to register the tag at the top of the code like this:

Code:
<%@ Register TagPrefix="uc1" TagName="ReportMenu" Src="Controls/ReportMenu.ascx" %>

now wherever you want to place this you add this tag:

Code:
<uc1:ReportMenu id="ReportMenu1" runat="server"></uc1:ReportMenu>

HTH
Bassguy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top