Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2006, 06:27 AM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default Server Includes - ASP.Net equivalent

Hi All

I have a snippet of code that needs to be included in each Page_Load event. I am from an ASP background and used to achieve this through using includes. When adding an include () within the <script> tags it doesn't like it. I get:

Server includes are not allowed in server script tags

What would the nice and shiny asp.net2 equivalent be?

Ta

Rit
__________________
Rit
www.designandonline.co.uk
INSPIRE | CREATE | DELIVER
 
Old February 20th, 2006, 01:00 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Rit,

Although you can still use include files to include static content somewhere in the page, it's not recommended to do so. As you found out, you can also no longer include files within script tags (you never could, BTW)

In .NET, there are much better and efficient means to reuse content and functionality.

If you want to share presentation, you can use User Controls (files ending with an .ascx extension). These controls, little ASPX pages, can hold controls, markup etc and can have Code Behind files like .aspx pages do.

If you want to reuse functionality (e.g. functions doing things, or returning stuff), in ASP.NET 2 you have a couple of options.

First of all, you can create a class file in the App_Code folder that contains shared or instance methods. From your ASPX pages, you can access these classes and methods.

Alternatively, you can create a Class Library project. At first sight, this looks like classes in the App_Code folder (in terms of how you can access the code), but it allows you to create an assembly that can be reused across multiple applications.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 21st, 2006, 10:31 AM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default

Always helpful. Many thanks Imar.

Rit





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP Includes in .NET sabu21s Classic ASP Databases 0 October 20th, 2005 04:43 PM
ASP Includes in XSL Alexpizzoferro XSLT 1 June 2nd, 2005 02:47 PM
A Yes/No dialog equivalent under asp.net badgolfer ASP.NET 1.0 and 1.1 Basics 2 June 11th, 2004 09:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.