including plain classes in pages

  • Thread starter Thread starter Daves
  • Start date Start date
D

Daves

now let's say I have a class that I want to include in all my aspx pages.
It's just a simple class containing some properties and constants. Since
it's not a user control (aka @Register ...) - how would I include it in my
pages? And should I create a .bin assembly for this or just a .cs file?
 
now let's say I have a class that I want to include in all my aspx pages.
It's just a simple class containing some properties and constants. Since
it's not a user control (aka @Register ...) - how would I include it in my
pages?

public class CGlobal
{
public static string strSomeGlobalValue()
{
return "Hello world!";
}
}

Then, from anywhere in the rest of your application:

string strHelloWorld = CGlobal.strSomeGlobalValue();
And should I create a .bin assembly for this or just a .cs file?

No need to create a separate assembly.

Alternatively, you could store the values in web.config.
 
thx - still, if I don't want to type it into every aspx file and even access
it from
PreRequestHandlerExecute event handler... how would I do that smoothly?
 
thx - still, if I don't want to type it into every aspx file and even
access it from
PreRequestHandlerExecute event handler... how would I do that smoothly?

I appear to have confused you...

You create a *separate* .cs file, name it CGlobal.cs, and add the class
definition to it - you don't add this to every page. In this way, it will be
available to your entire application as and when required.
 
Back
Top