Link to home
Start Free TrialLog in
Avatar of bemara57
bemara57

asked on

Where to declare read only static global class (ASP.NET 2.0 / C#)?

I want to make a global static class available to my aspx.cs pages. Should I declare this class in a separate .cs file in the App_Code folder? How do I call it from the aspx.cs page if I don't initialize the class? I want to make several different global classes and tell different aspx.cs pages which one to choose and use. It's really for my class below. Can someone help?

I want the aspx.cs to either pick:
(ConfigXML)WebConfigurationManager.GetSection("Test_id1");

Or:
(ConfigXML)WebConfigurationManager.GetSection("Test_id2");

Or:
(ConfigXML)WebConfigurationManager.GetSection("Test_id3");

I want to code my aspx.cs to tell it which one to do.
Avatar of raterus
raterus
Flag of United States of America image

All classes must first be instantiated before they can be used.  However you can create static methods in those classes, and use them without instantiating the class.  Is that what you mean?
Avatar of bemara57
bemara57

ASKER

Yes, because these values will never change unless the web app is restarted. They are global settings for the website for any user to use.
You mean something like this?

App_Code/MyClass.cs
===============================================
using (whatevers)

namespace MyProject
{
public class MyClass
{
pPublic static void MyFunction(string sSection)
{
(ConfigXML)WebConfigurationManager.GetSection(sSection);
}
}
}


Default.asp.cs
===============================================
Page_Load

MyProject.MyClass.MyFunction("Test_id1");
ASKER CERTIFIED SOLUTION
Avatar of raterus
raterus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial