Global Function and Variables

S

Simon Harris

Hi All,

I'm new to ASP.Net, so be gentle! (Plenty of 'classic' ASP experience), just
one question...

- Am I correct in thinking that global functions are stored in ASCX files?

Thanks!

Simon.

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!
 
G

George Ter-Saakov

No you are incorrect.
But i feel where are you coming from.

In ASP.NET if you wanted to create reusable HTML element you would create
file with a global function and include it everywhere.

And whenever you need that HTML to appear you would call that global
function.

Am i correct?

The User Control(s) - ascx file is much better choice than simple include.
I would not call it a global function though.


George.
 
S

Scott Mitchell [MVP]

I'm new to ASP.Net, so be gentle! (Plenty of 'classic' ASP experience), just
one question...

- Am I correct in thinking that global functions are stored in ASCX files?

No, ASCX files, or User Controls, contain reusable user interface
pieces. Check out my article on User Controls for an in-depth
examination of User Controls:

An Extensive Examination of User Controls
http://msdn.microsoft.com/asp.net/u...l=/library/en-us/dnaspp/html/usercontrols.asp

For information on global variables and functions, check out this article:

Accessing Common Code, Constants, and Functions in an ASP.NET Project
http://aspnet.4guysfromrolla.com/articles/122403-1.aspx

Happy Programming!
 
K

Kevin Spencer

Hi Simon,

I would recommend reading up on Object-Oriented programming. The paradigm
for OOP is entirely different from procedural programming, and unless you
understand the principles, you will continually be confounded. ASP is
procedural, meaning that the programming instructions contained in an ASP
page/script are executed in the order in which they appear in the
script/page, including the rendering of HTML in the page. ASP.Net is
Object-oriented, meaning that programming instructions are not in a script
and are not executed sequentially. Therefore, there is no such thing as a
"global function." There is Scope, but Scope is defined differently. Rather
than functions that are simply defined and called as needed, there are
classes, which are aggregates of data and functionality bundled together in
an encapsulation. The class is a container, if you will, for these various
functions and data. It doesn't execute in the procedural sense, but behaves
more like an object which can be used by another object.

The term "global," and the concept of Scope in general, are different.
Members of a class are "global" to the class; that is, they are accessible
to all class members. A class can have members that are not available
outside of the class, or to any class which doesn't inherit the class, or
are visible to any entity outside of the class. These members are scoped as
Private, Public, Protected, etc. In addition, you have the same general
types of scope that exist in an ASP application, such as the Application,
which is globally available to all classes in the application, Session,
which is global to all page instances of a single user, and so on.

Again, as ASP.Net is not procedural, it is not hepful to think of functions,
classes, and other programming objects as being "in files." ASP.Net is not
scripted, but compiled. Classes and other programming elements reside in
NameSpaces, and in assemblies. The files are simply a storage container for
the code. The file is not important; the code is. Object-oriented
programming is a good bit more abstract than procedural, but once you start
thinking object-oriented, it all snaps neatly into place.

In any case, you should be able to see now that a basic understanding of
Object-Oriented programming principles is essential to writing an ASP.Net
application.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
S

Simon Harris

Kevin Spencer said:
Hi Simon,

I would recommend reading up on Object-Oriented programming. The paradigm
for OOP is entirely different from procedural programming, and unless you
understand the principles, you will continually be confounded. ASP is
procedural, meaning that the programming instructions contained in an ASP
page/script are executed in the order in which they appear in the
script/page, including the rendering of HTML in the page. ASP.Net is
Object-oriented, meaning that programming instructions are not in a script
and are not executed sequentially. Therefore, there is no such thing as a
"global function." There is Scope, but Scope is defined differently. Rather
than functions that are simply defined and called as needed, there are
classes, which are aggregates of data and functionality bundled together in
an encapsulation. The class is a container, if you will, for these various
functions and data. It doesn't execute in the procedural sense, but behaves
more like an object which can be used by another object.

The term "global," and the concept of Scope in general, are different.
Members of a class are "global" to the class; that is, they are accessible
to all class members. A class can have members that are not available
outside of the class, or to any class which doesn't inherit the class, or
are visible to any entity outside of the class. These members are scoped as
Private, Public, Protected, etc. In addition, you have the same general
types of scope that exist in an ASP application, such as the Application,
which is globally available to all classes in the application, Session,
which is global to all page instances of a single user, and so on.

Again, as ASP.Net is not procedural, it is not hepful to think of functions,
classes, and other programming objects as being "in files." ASP.Net is not
scripted, but compiled. Classes and other programming elements reside in
NameSpaces, and in assemblies. The files are simply a storage container for
the code. The file is not important; the code is. Object-oriented
programming is a good bit more abstract than procedural, but once you start
thinking object-oriented, it all snaps neatly into place.

In any case, you should be able to see now that a basic understanding of
Object-Oriented programming principles is essential to writing an ASP.Net
application.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.


Hi Kevin,

Thanks for the explanation, I will certainly have a read about OOP
concepts - It seems your right in that the basic concepts will be helpful in
making the rest 'snap into place'

Sounds to me also like ASP.Net is going to be a rather steep learning curve
for some one with no 'proper' coding knowledge - My experience is solely
self taught classic ASP and JavaScript over the past 4-5 years, building
Intranet applications.

Here goes with some hefty study sessions! :)

Regards,
Simon
 
K

Kevin Spencer

Hi Simon,

A Steep learning curve, yes. Worth the effort? Most definitely! And again,
once you "get" OOP, the programming paradigm snaps into place pretty well.
In fact, I consider it easier to work with, more organized, more
encapsulated. The hard part is finding the functionality you want in the
CLR. But the .Net SDK, which is a free download, makes that job much easier
as well. If you want a free copy of the .Net SDK, see:

http://www.microsoft.com/downloads/...A6-3647-4070-9F41-A333C6B9181D&displaylang=en

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top