How to include a file in ASP.NET

  • Thread starter Thread starter HNguyen
  • Start date Start date
H

HNguyen

Hi all,

I don't know how to include the files from an .aspx file using Visual
Studio.NET. For example, I have a file containing the constants and I want
to use these constants from aspx file. Could you tell me the good way to do
that ? Thank you.
 
Create a class. Put the constants into the class. Use the class.

Or -

Put the constants into your web.config file, if you may want to change their
values later. Use the web.config file.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
HNGuyan:

you have a class with constats:

public class Settings
public const SiteId as Integer = 1
public const DefaultName as String = "EComZ"
end class


you can then access the values via:

Settings.SiteId
and
Settings.DefaultName

Consider building more functionality by using a custom configuration
(http://openmymind.net/Configuration/index.html). This will allow you to
change settings in the web.config.

Karl
 
Thank you, Kevin. I tried to put the constants in the class and call them
from other pages; it worked fine. How about declaring these constants in the
global.asax file or loading these constant in the Cache to use in other
pages. Is it a good way ? Thank you.
 
It is important to think in object-oriented terms here: The global.asax FILE
is not part of your application. The Global CLASS is. So, yes, putting your
constants into the Global class would work, just as putting them into any
other class would work. As to whether or not you SHOULD put them there,
well, that depends on what the constants are used for. I recently lost my
check book. I looked for it for several days, and today I found it in a bag
that had a Valentine's Day card I had bought for my wife. In other words,
the reason I "lost" it was, I didn't take the effort to put it where it
belonged (logically). Classes are a great way to organize data and process.
As far as the app is concerned, it doesn' tmatter what class you put it in.
As far as YOU'RE concerned, it matters a lot.

As for caching them, well, they are constants. If you make them static, they
won't need to be cached, and you won't need an instance of a class to use
them. If you ever want to change them for future deployment or whatever,
storing them in the web.config file enables you to change them without
having to recompile.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
Back
Top