Re: Best place for "Global Variables" and Methods in C# though ASP.Net
- From: "IfThenElse" <sql_agentman@xxxxxxxxxxx>
- Date: Wed, 17 Oct 2007 08:56:03 -0700
in addition use the web.config for encrypted connection string and other
configurations, may additionally use XML config files etc..
may want to have some aspx pages inherit from some base with common
functionality.
"Mark Rae [MVP]" <mark@xxxxxxxxxxxxxxxxx> wrote in message
news:eLrqPGNEIHA.1184@xxxxxxxxxxxxxxxxxxxxxxx
<Bub.Paulson@xxxxxxxxx> wrote in message
news:1192633761.366425.219980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
A month ago I finally took the plunge and began learning C# and
ASP.Net, coming from a Classic ASP and VBScript background.
In my classic ASP, I had my own little library of code that I stuck in
an include file called "Common_VBscript.asp" which had all of the
common stuff I used. (Constants, Connection Strings, little utlities
like "email validation" functions, or functions to ready strings for
db entry, etc.)
What is the best way for me to have a "common code" module tacked on
to all (or many) of my ASP.Net pages for a particular project? And
how can I do it, precisely?
ASP.NET, like the rest of the .NET Framework, is object-orientated.
Generally speaking, if you're looking for "global" anything, you probably
need a bit of a refresher on OOP...
An obvious solution is to create a new class with common functions. Then,
whenever you need one or more of them, just instantiate the class and use
the function(s) you need...
In addition, C# supports classes with static methods which you can use
anywhere in your code without instantiating the class. Purists may flinch
at doing this, but it can be useful:
http://www.eggheadcafe.com/articles/20020206.asp
And, purely in the interests of balance, VB.NET can do the same thing with
its Shared methods...
However, be very wary of static variables, as they will be common across
all sessions, which can lead to some very unexpected and unwanted
results...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
.
- References:
- Best place for "Global Variables" and Methods in C# though ASP.Net
- From: Bub . Paulson
- Re: Best place for "Global Variables" and Methods in C# though ASP.Net
- From: Mark Rae [MVP]
- Best place for "Global Variables" and Methods in C# though ASP.Net
- Prev by Date: Re: Retrieving ObjectDataSource columns
- Next by Date: Re: javascript in page load
- Previous by thread: Re: Best place for "Global Variables" and Methods in C# though ASP.Net
- Next by thread: Re: Best place for "Global Variables" and Methods in C# though ASP.Net
- Index(es):
Relevant Pages
|