By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,025 Members | 2,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,025 IT Pros & Developers. It's quick & easy.

.Net "include" files

P: n/a
Howdy

I want to simulate with .Net what I used to do with classic ASP where you
would have a series of include files with utility functions that you would
include when you needed them.

I read some article about creating a utility class, but it gave no details,
and I'm not sure what to do. Do I create a .cs file and then just include
it? What should the class inherit from? And how do you inherit more than one
class on your page in order to use the utility class?

Clearly there's a understanding gap I've got here, any pointers/links etc.
would be greatly appreciated.
Cheers
Matt

Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
If you just have some miscallaneous functionality, you create a static
methods inside a class

public class Utility
{
public static in Adder(int x, int y)
{
return x + y; //what about overflows, oh oh!
}
}

which you can then use via

Utility.Adder(1,2)
if your Utility class and your consuming class aren't in the same namespace,
you either have to import (via using) the Utility's namespace, or fully
reference it via Namespace.Utility.Adder()

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Matt Jensen" <re***************@microsoft.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Howdy

I want to simulate with .Net what I used to do with classic ASP where you
would have a series of include files with utility functions that you would
include when you needed them.

I read some article about creating a utility class, but it gave no
details,
and I'm not sure what to do. Do I create a .cs file and then just include
it? What should the class inherit from? And how do you inherit more than
one
class on your page in order to use the utility class?

Clearly there's a understanding gap I've got here, any pointers/links etc.
would be greatly appreciated.
Cheers
Matt

Nov 19 '05 #2

P: n/a
Because of ASP's procedural nature, the use of include files to include
other files of scripting code was a necessity, a way of achieving code
reusability in a procedural, scripting technology. As ASP.Net is both
object-oriented, and fully compiled, the use of include files is not
generally a good practice. If one is using include files that contain
pre-processor code, all well and good. But to use include files for
executable code is a big mistake.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Expect the unaccepted.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:um**************@TK2MSFTNGP10.phx.gbl...
If you just have some miscallaneous functionality, you create a static
methods inside a class

public class Utility
{
public static in Adder(int x, int y)
{
return x + y; //what about overflows, oh oh!
}
}

which you can then use via

Utility.Adder(1,2)
if your Utility class and your consuming class aren't in the same
namespace, you either have to import (via using) the Utility's namespace,
or fully reference it via Namespace.Utility.Adder()

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Matt Jensen" <re***************@microsoft.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Howdy

I want to simulate with .Net what I used to do with classic ASP where you
would have a series of include files with utility functions that you
would
include when you needed them.

I read some article about creating a utility class, but it gave no
details,
and I'm not sure what to do. Do I create a .cs file and then just include
it? What should the class inherit from? And how do you inherit more than
one
class on your page in order to use the utility class?

Clearly there's a understanding gap I've got here, any pointers/links
etc.
would be greatly appreciated.
Cheers
Matt


Nov 19 '05 #3

P: n/a
Thanks guys
I'm essentially using notepad at the moment, if that makes a
difference.... - I don't understanding how making a simple 'using' call to
the namespace manages to locate the class...?
Thanks for any enlightenment :-)
Matt
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:um**************@TK2MSFTNGP10.phx.gbl...
If you just have some miscallaneous functionality, you create a static
methods inside a class

public class Utility
{
public static in Adder(int x, int y)
{
return x + y; //what about overflows, oh oh!
}
}

which you can then use via

Utility.Adder(1,2)
if your Utility class and your consuming class aren't in the same
namespace, you either have to import (via using) the Utility's namespace,
or fully reference it via Namespace.Utility.Adder()

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Matt Jensen" <re***************@microsoft.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Howdy

I want to simulate with .Net what I used to do with classic ASP where you
would have a series of include files with utility functions that you
would
include when you needed them.

I read some article about creating a utility class, but it gave no
details,
and I'm not sure what to do. Do I create a .cs file and then just include
it? What should the class inherit from? And how do you inherit more than
one
class on your page in order to use the utility class?

Clearly there's a understanding gap I've got here, any pointers/links
etc.
would be greatly appreciated.
Cheers
Matt


Nov 19 '05 #4

P: n/a
As ASP.Net is object-oriented and fully compiled, it makes no difference
what tools you use to write your code. Remember, this is not procedural
scripting.

Are you using CodeBehind, or a Siingle-File WebForm? I would recommend using
CodeBehind classes, as it separates the UI business logic from the Template
code, making it easier to manage. You could put your CodeBehind files into
the bin directory, as well as the classes (class files) you create. Then
(you're using VB.Net, right?) you would simply use an Imports NameSpace
statement in the CodeBehind to use the external classes.

Another alternative (although this is not as pretty) is to define multiple
classes in the same file. Of course, this makes reusing your business
classes much more difficult.

You may find the following MSDN Library article helpful:

http://msdn.microsoft.com/library/de...scodemodel.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Expect the unaccepted.

"Matt Jensen" <re***************@microsoft.com> wrote in message
news:un**************@TK2MSFTNGP14.phx.gbl...
Thanks guys
I'm essentially using notepad at the moment, if that makes a
difference.... - I don't understanding how making a simple 'using' call to
the namespace manages to locate the class...?
Thanks for any enlightenment :-)
Matt
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:um**************@TK2MSFTNGP10.phx.gbl...
If you just have some miscallaneous functionality, you create a static
methods inside a class

public class Utility
{
public static in Adder(int x, int y)
{
return x + y; //what about overflows, oh oh!
}
}

which you can then use via

Utility.Adder(1,2)
if your Utility class and your consuming class aren't in the same
namespace, you either have to import (via using) the Utility's namespace,
or fully reference it via Namespace.Utility.Adder()

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Matt Jensen" <re***************@microsoft.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Howdy

I want to simulate with .Net what I used to do with classic ASP where
you
would have a series of include files with utility functions that you
would
include when you needed them.

I read some article about creating a utility class, but it gave no
details,
and I'm not sure what to do. Do I create a .cs file and then just
include
it? What should the class inherit from? And how do you inherit more than
one
class on your page in order to use the utility class?

Clearly there's a understanding gap I've got here, any pointers/links
etc.
would be greatly appreciated.
Cheers
Matt



Nov 19 '05 #5

P: n/a
Include files are old fashioned.
User controls are a common replacement for reusable bits of UI and related
code.
You can create public properties, methods, and events to facilitate
communication between the user control and the page.
Even better is the "Master Pages" functionality that will be included with
ASP.NET 2.0.

Here's more info:
http://SteveOrr.net/faq/UserCustom.aspx
http://aspnet.4guysfromrolla.com/articles/010505-1.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Matt Jensen" <re***************@microsoft.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Howdy

I want to simulate with .Net what I used to do with classic ASP where you
would have a series of include files with utility functions that you would
include when you needed them.

I read some article about creating a utility class, but it gave no
details,
and I'm not sure what to do. Do I create a .cs file and then just include
it? What should the class inherit from? And how do you inherit more than
one
class on your page in order to use the utility class?

Clearly there's a understanding gap I've got here, any pointers/links etc.
would be greatly appreciated.
Cheers
Matt

Nov 19 '05 #6

P: n/a
re:
I read some article about creating a utility class, but it gave no details, and I'm not
sure what to do. Do I create a .cs file and then just include it?
What I do is write my classes/methods/properties in a .cs ( or .vb )
file and compile it from the command-line. That creates an assembly
which I call it utilities.dll, original, huh ? :-) which I place in the bin directory.

Then, it's a simple thing to call the
classes/methods/properties in my .aspx files.

The classes/methods/properties can be called from any .aspx page.

As others have suggested, writing user controls works, too,
although I find it simpler to use a hand-compiled assembly for utillities.

To compile a single file, use :

csc /t:library /out:utils.dll utils.cs

To compile all .cs files in a directory to utils.dll , use :
csc /t:library /out:utils.dll *.cs

If you need to reference a library/libraries,
add it/them, separated by slashes :

csc /t:library /r:system.dll /r:system.data.dll /out:utils.dll *.cs

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Matt Jensen" <re***************@microsoft.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl... Howdy

I want to simulate with .Net what I used to do with classic ASP where you
would have a series of include files with utility functions that you would
include when you needed them.

I read some article about creating a utility class, but it gave no details,
and I'm not sure what to do. Do I create a .cs file and then just include
it? What should the class inherit from? And how do you inherit more than one
class on your page in order to use the utility class?

Clearly there's a understanding gap I've got here, any pointers/links etc.
would be greatly appreciated.
Cheers
Matt

Nov 19 '05 #7

P: n/a
Thanks for all this guys
I'll check it out and get back to you
Cheers
Matt

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
re:
I read some article about creating a utility class, but it gave no
details, and I'm not sure what to do. Do I create a .cs file and then
just include it?


What I do is write my classes/methods/properties in a .cs ( or .vb )
file and compile it from the command-line. That creates an assembly
which I call it utilities.dll, original, huh ? :-) which I place in the
bin directory.

Then, it's a simple thing to call the
classes/methods/properties in my .aspx files.

The classes/methods/properties can be called from any .aspx page.

As others have suggested, writing user controls works, too,
although I find it simpler to use a hand-compiled assembly for utillities.

To compile a single file, use :

csc /t:library /out:utils.dll utils.cs

To compile all .cs files in a directory to utils.dll , use :
csc /t:library /out:utils.dll *.cs

If you need to reference a library/libraries,
add it/them, separated by slashes :

csc /t:library /r:system.dll /r:system.data.dll /out:utils.dll *.cs

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Matt Jensen" <re***************@microsoft.com> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
Howdy

I want to simulate with .Net what I used to do with classic ASP where you
would have a series of include files with utility functions that you
would
include when you needed them.

I read some article about creating a utility class, but it gave no
details,
and I'm not sure what to do. Do I create a .cs file and then just include
it? What should the class inherit from? And how do you inherit more than
one
class on your page in order to use the utility class?

Clearly there's a understanding gap I've got here, any pointers/links
etc.
would be greatly appreciated.
Cheers
Matt


Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.