473,322 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

.Net "include" files

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
7 2213
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
2
by: steve | last post by:
Hi, I need to do conditional script "include", but like to pull the code from db instead of a file. How do I do that? Reason: I like to implement some complex regex logic, and make it table...
4
by: Simon Wigzell | last post by:
I often use : <!--#include file="filename"--> in my code to include often used bits of asp code. I told someone in another newsgroup about it but now I'm wondering if it will be supported for...
7
by: mescaline | last post by:
Hi, Suppose a_file.cpp contains a function a_function() Now to include it in main_file.cpp I just do #include "a_file.cpp" and I'm all set. i recently came across this seemingly roundabout...
4
by: Exits Funnel | last post by:
Hello, I'm slightly confused about when to use parens around #included files and when to use angle brackets. I understand (I think) that the difference is that the compiler will search in its...
18
by: Tuckers | last post by:
My question is, if I have created my own library which lives in its own install directory, to refer to its header file is it better to use #include "MyLibrary.h" or #include <MyLibrary.h> ...
4
by: bibsoconner | last post by:
Hi, I hope someone can please help me. I'm having a lot of trouble with schema files in .NET. I have produced a very simple example that uses "include" to include other schema files. It all...
1
by: Colin Caughie | last post by:
Is there a general rule/convention for when to use angle brackets and when to use quotes in #include statements? Is the angle bracket reserved for "system" header files (e.g. standard library...
12
by: Pablo Suarez | last post by:
When I code #include "myheader.h" then this header file is searched in the current directory. But where does the compiler search the header file when I write #include <myheader.h>
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.