Where to keep gloabal function

I am working in VS2005 ASP.NET 2.0 Sqlserver 2000.
I have in my project some functions that I use in every page like show error message.
Where should I keey them?
I thought of creating a .cs file in the App_Code folder and I pit there a public function but when I calles it from the codebehind of a page it was not recognized.
ANAT2403Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
Hi ANAT2403,

You should be able to create a .cs file there called lets say "Globals" and then create your functions as shared:

Public Shared Function MyError(ByVal TheMessage As String)

Then call it as

Globals.MyError ("Message")

The key part is to make it a shared function, that way you do not need to create an instance of the class.

Tim Cottee
ANAT2403Author Commented:
What you wrote is good for visual basic. I am working in C#.
there is no "shared" but what I define in App_code is public. But from what I read I have to
define it as a class .
 In the msdn:  " Using Shared Code in Web Sites in Visual Web Developer " 
so it doesn't work for me. first I tried to write ther a function but I coudn't call it and I don't know how to define it
as a class. This is my function:

public void ShowMessage(string keymsg,Page page)
    {
        string msg = (string)GetGlobalResourceObject("Messages", keymsg);
        string myScript = @"alert('" + msg + "')";
        page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", myScript, true);
    }
praneethaCommented:
shared is equivalent to static in C# if i am nto wrong

so once u declare the mehtod as static you can call ut using Globals.ShowMEssage.

good luck

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
enwhyseeCommented:
Yep, static would work in C# as praneetha mentions. So you could make a class that is called Globals, and then define the method as follows:

public class Globals
{
    public static void ShowMessage(string keymsg,Page page)
    {
        string msg = (string)HttpContext.GetGlobalResourceObject("Messages", keymsg);
        string myScript = @"alert('" + msg + "')";
        page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", myScript, true);
    }
}


Then, elsewhere, you could say  Globals.ShowMessage("blah", myPage); and it will work.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.