Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 May 24th, 2004, 06:48 PM
Registered User
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How Can I #INCLUDE Multiple Source Files Like in A

I would like to manage my groups of routines and classes in separate files. I could do this in ASP using the #INCLUDE statement. How does one do this technique in Asp.Net? Asp.Net seems to only allow one code-behind file forcing all code to be in one file. This is a mangement nightmare. I hope Asp.Net is not this restrictive.

Thank you,

--Llyal
 
Old May 24th, 2004, 07:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

In your project, you declare a class or module:

Public Class MyClass

OR

Public Module MyModule

You can call these at any scope within your application, so in your code behind file, you can make a call to

private sub Page_Load(..)
  Dim objClass as New MyClass
  Response.Write(objClass.MyMethod(..))
end sub

And do whatever with these methods. Alternatively if you declare a method as shared (VB.NET) or static (C#), you can call it without instantiating the object:

private sub Page_Load(..)
  Response.Write(MyClass.MyMethod(..))
end sub

Hope this helps,

Brian
 
Old May 24th, 2004, 08:44 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

In your ASP.net project, you can add a class file. This is a single file with an extension for the language you are using (.vb or .cs). These files can live anywhere within the web application project and will get compiled with the code-behind of the pages. All of your shared functions will then be accessible to the code in the code-behind.

Group the functions into classes to organize common functionality. In many cases, especially if you are looking to create simple functions, you can declare the functions so that you do not need an instance of their parent class to use them. Normally, you need to instantiate the class to call one of its methods. Using the keyword "Shared" in VB.net or "static" in C# causes the method to be accessible without the need for a class instance. This way you can call the function directly by the class name and method name: MyClass.MyMethod().

Peter
-------------------------
Work smarter, not harder





Similar Threads
Thread Thread Starter Forum Replies Last Post
include files b00gieman Classic ASP Basics 2 September 15th, 2007 10:22 AM
Include files tarang SQL Server 2000 1 July 18th, 2007 03:32 AM
Include Files jmss66 Classic ASP Basics 16 June 9th, 2004 10:20 PM





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