473,554 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to call a Sub function from .ASPX file ?

Hi,

I have a question about file included in ASP.NET. I have a file that
includes all the Sub functions (e.g FileFunct.vb). One of the functions
in this file is :

Sub TestFunct(ByVal strInput As String)
return (strInput & " test")
End Sub
I'd like to call this function in FileFunct.vb from another .ASPX file
like this :

<%@ import Namespace="Syst em" %>
<%@ import Namespace="Syst em.Data" %>

<html>
<head>
<title>Test page</title>
</head>

<body>
<script runat="server" language="VB" scr="FileFunct. vb" >

Sub Page_Load(s As Object, e As EventArgs)
Dim result=TestFunc t("This is a string")
response.write( "<BR>result ==> " & result)
End Sub
</script>
</body>
</html>

I've got this error:

Server Error in '/' Application.
----------------------------------------------------------------------------
----

Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'TestFunct' is not declared.

Source Error:
Line 18: Sub Page_Load(s As Object, e As EventArgs)
Line 19:
Line 20: Dim result=TestFunc t("This is a string")
Line 21: response.write( "<BR>Result ==> " & Result)
Line 22:
I have a single .ASPX file and I don't use Visual studio. NET in this case.
Can I do that ?

Thanks in advance.
Nov 19 '05 #1
10 24049
Make TestFunc shared and access it via

ClassName.TextF unc

so, it would look like

public class Utility
public shared TestFunct(..)
...
end function
end class

and you would use it like:

Utility.TestFun ct(...)

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!)
"bienwell" <bi******@hotma il.com> wrote in message
news:O7******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I have a question about file included in ASP.NET. I have a file that
includes all the Sub functions (e.g FileFunct.vb). One of the functions
in this file is :

Sub TestFunct(ByVal strInput As String)
return (strInput & " test")
End Sub
I'd like to call this function in FileFunct.vb from another .ASPX file
like this :

<%@ import Namespace="Syst em" %>
<%@ import Namespace="Syst em.Data" %>

<html>
<head>
<title>Test page</title>
</head>

<body>
<script runat="server" language="VB" scr="FileFunct. vb" >

Sub Page_Load(s As Object, e As EventArgs)
Dim result=TestFunc t("This is a string")
response.write( "<BR>result ==> " & result)
End Sub
</script>
</body>
</html>

I've got this error:

Server Error in '/' Application.
----------------------------------------------------------------------------
----

Compilation Error
Description: An error occurred during the compilation of a resource
required
to service this request. Please review the following specific error
details
and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'TestFunct' is not declared.

Source Error:
Line 18: Sub Page_Load(s As Object, e As EventArgs)
Line 19:
Line 20: Dim result=TestFunc t("This is a string")
Line 21: response.write( "<BR>Result ==> " & Result)
Line 22:
I have a single .ASPX file and I don't use Visual studio. NET in this
case.
Can I do that ?

Thanks in advance.

Nov 19 '05 #2
You're not thinking fourth-dimensionally! (- Back to the Future)

Actually, you're not thinking Object-Orientationally .

ASP.Net is object-oriented, and you'd better get acquainted with it, or
you'll be visiting here almost daily, and writing crappy code until you do.
Let me elaborate, if you will:

Files are source code. Your application doesn't have files. It has classes.
A file defines a class, but IS not a class. A class is a data type, and
exists in the context of a running application. So, when you're talking
about how your application works, the first thing you need to do is think
about classes, not files. A file can contain one or MORE class definitions,
and you need to get acquainted with classes to be successful with .Net.

Classes are very important in .Net programming; Objects are made from
classes, and classes provide encapsulation. Object-oriented programming can
get pretty darned complex, and encapsulation can save you a lot of grief, by
hiding those things which need hiding from those things that don't need
them.

If you have a file with a bunch of Subs and Functions in it, you need to
create a class with Subs and Functions in it. These Subs and Functions can
be Shared (meaning that they are singleton objects that don't require a
class instance to operate), or they can be Instance (meaning that an
instance of the class containing them must be created in order to use them).
The advantage to Shared data and process is that it doesn't require a class
instance, and is, in essence "global," available to the entire application.
This is also the disadvantage of Shared data and process. Anything can get
to it, and change it, and in a multi-threaded app (unlike VB 6, .net is
multi-threaded), this can cause all sorts of problems. Unless you're
familiar with the issues, I would stick with classes that require
instantiation. Instantiation is the process of creating a copy (instance) of
a class that is limited in its scope (availability), and is thread-safe.

Once you create an instance of a class, you can access any Public or Friend
(Friend is more protected than Public, but you shouldn't run into issues
right away) members from any other class that references the instance.

From your question, and the code you posted, I can see that you require a
good bit more education and practice. I would recommend the .Net SDK, a free
download from:

http://www.microsoft.com/downloads/d...displaylang=en

It is extremely important to know the difference between ASP and ASP.Net,
between VBScript or VB 6, and VB.Net. The first are procedural,
single-threaded, and easy to use for small applications. .Net is
object-oriented, multi-threaded, and easy to use once you spend a great deal
of time studying it, but incredibly hard to use if you don't.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"bienwell" <bi******@hotma il.com> wrote in message
news:O7******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I have a question about file included in ASP.NET. I have a file that
includes all the Sub functions (e.g FileFunct.vb). One of the functions
in this file is :

Sub TestFunct(ByVal strInput As String)
return (strInput & " test")
End Sub
I'd like to call this function in FileFunct.vb from another .ASPX file
like this :

<%@ import Namespace="Syst em" %>
<%@ import Namespace="Syst em.Data" %>

<html>
<head>
<title>Test page</title>
</head>

<body>
<script runat="server" language="VB" scr="FileFunct. vb" >

Sub Page_Load(s As Object, e As EventArgs)
Dim result=TestFunc t("This is a string")
response.write( "<BR>result ==> " & result)
End Sub
</script>
</body>
</html>

I've got this error:

Server Error in '/' Application.
----------------------------------------------------------------------------
----

Compilation Error
Description: An error occurred during the compilation of a resource
required
to service this request. Please review the following specific error
details
and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'TestFunct' is not declared.

Source Error:
Line 18: Sub Page_Load(s As Object, e As EventArgs)
Line 19:
Line 20: Dim result=TestFunc t("This is a string")
Line 21: response.write( "<BR>Result ==> " & Result)
Line 22:
I have a single .ASPX file and I don't use Visual studio. NET in this
case.
Can I do that ?

Thanks in advance.

Nov 19 '05 #3
Kevin,

Last time I put all the files in my application (project name) using Visual
Studio.NET, declared a class (AClass) which has some functions, and saved
them in a file (.vb file). My program worked fine when I called the function
from my other .vb files (AClass.Functio n1, ...). My application was
Object-Oriented well development. Now, I'd like to try another way :
creating .ASPX file that contains VB.NET script, HTML and call one function
from another .vb file without using Visual Studio.NET. Can I do that and How
? It's my question.


"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:u7******** ******@TK2MSFTN GP15.phx.gbl...
You're not thinking fourth-dimensionally! (- Back to the Future)

Actually, you're not thinking Object-Orientationally .

ASP.Net is object-oriented, and you'd better get acquainted with it, or
you'll be visiting here almost daily, and writing crappy code until you do. Let me elaborate, if you will:

Files are source code. Your application doesn't have files. It has classes. A file defines a class, but IS not a class. A class is a data type, and
exists in the context of a running application. So, when you're talking
about how your application works, the first thing you need to do is think
about classes, not files. A file can contain one or MORE class definitions, and you need to get acquainted with classes to be successful with .Net.

Classes are very important in .Net programming; Objects are made from
classes, and classes provide encapsulation. Object-oriented programming can get pretty darned complex, and encapsulation can save you a lot of grief, by hiding those things which need hiding from those things that don't need
them.

If you have a file with a bunch of Subs and Functions in it, you need to
create a class with Subs and Functions in it. These Subs and Functions can
be Shared (meaning that they are singleton objects that don't require a
class instance to operate), or they can be Instance (meaning that an
instance of the class containing them must be created in order to use them). The advantage to Shared data and process is that it doesn't require a class instance, and is, in essence "global," available to the entire application. This is also the disadvantage of Shared data and process. Anything can get
to it, and change it, and in a multi-threaded app (unlike VB 6, .net is
multi-threaded), this can cause all sorts of problems. Unless you're
familiar with the issues, I would stick with classes that require
instantiation. Instantiation is the process of creating a copy (instance) of a class that is limited in its scope (availability), and is thread-safe.

Once you create an instance of a class, you can access any Public or Friend (Friend is more protected than Public, but you shouldn't run into issues
right away) members from any other class that references the instance.

From your question, and the code you posted, I can see that you require a
good bit more education and practice. I would recommend the .Net SDK, a free download from:

http://www.microsoft.com/downloads/d...displaylang=en
It is extremely important to know the difference between ASP and ASP.Net,
between VBScript or VB 6, and VB.Net. The first are procedural,
single-threaded, and easy to use for small applications. .Net is
object-oriented, multi-threaded, and easy to use once you spend a great deal of time studying it, but incredibly hard to use if you don't.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"bienwell" <bi******@hotma il.com> wrote in message
news:O7******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I have a question about file included in ASP.NET. I have a file that
includes all the Sub functions (e.g FileFunct.vb). One of the functions in this file is :

Sub TestFunct(ByVal strInput As String)
return (strInput & " test")
End Sub
I'd like to call this function in FileFunct.vb from another .ASPX file
like this :

<%@ import Namespace="Syst em" %>
<%@ import Namespace="Syst em.Data" %>

<html>
<head>
<title>Test page</title>
</head>

<body>
<script runat="server" language="VB" scr="FileFunct. vb" >

Sub Page_Load(s As Object, e As EventArgs)
Dim result=TestFunc t("This is a string")
response.write( "<BR>result ==> " & result)
End Sub
</script>
</body>
</html>

I've got this error:

Server Error in '/' Application.


--------------------------------------------------------------------------

--
----

Compilation Error
Description: An error occurred during the compilation of a resource
required
to service this request. Please review the following specific error
details
and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'TestFunct' is not declared.

Source Error:
Line 18: Sub Page_Load(s As Object, e As EventArgs)
Line 19:
Line 20: Dim result=TestFunc t("This is a string")
Line 21: response.write( "<BR>Result ==> " & Result)
Line 22:
I have a single .ASPX file and I don't use Visual studio. NET in this
case.
Can I do that ?

Thanks in advance.


Nov 19 '05 #4
Karl,

I've tried it like this:

(In Function.vb file)
Public Class EFiling_Funct
Public Shared Function TestFunct(ByVal strInput As String)
return (strInput & " test")
End Function
End Class

=============== =============== =============== ===
(in File1.ASPX file)

<%@ import Namespace="Syst em" %>
<%@ import Namespace="Syst em.Data" %>
<html>
<head>
<title>Untitled </title>

</head>

<body>
<script runat="server" language="VB" >

Sub Page_Load(s As Object, e As EventArgs)

Dim result=EFiling_ Funct.TestFunct ("This is a string")
response.write( "<BR>Result ==> " & Result)

End Sub
</script>

</body>
</html>
and received this error message :

Server Error in '/' Application.
----------------------------------------------------------------------------
----

Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'EFiling_Funct' is not declared.

Source Error:

Line 18: Sub Page_Load(s As Object, e As EventArgs)
Line 19:
Line 20: Dim result=EFiling_ Funct.TestFunct ("This is a string")
Line 21: response.write( "<BR>Result ==> " & Result)
Line 22:

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:us******** ******@TK2MSFTN GP14.phx.gbl...
Make TestFunc shared and access it via

ClassName.TextF unc

so, it would look like

public class Utility
public shared TestFunct(..)
...
end function
end class

and you would use it like:

Utility.TestFun ct(...)

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!)
"bienwell" <bi******@hotma il.com> wrote in message
news:O7******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I have a question about file included in ASP.NET. I have a file that
includes all the Sub functions (e.g FileFunct.vb). One of the functions in this file is :

Sub TestFunct(ByVal strInput As String)
return (strInput & " test")
End Sub
I'd like to call this function in FileFunct.vb from another .ASPX file
like this :

<%@ import Namespace="Syst em" %>
<%@ import Namespace="Syst em.Data" %>

<html>
<head>
<title>Test page</title>
</head>

<body>
<script runat="server" language="VB" scr="FileFunct. vb" >

Sub Page_Load(s As Object, e As EventArgs)
Dim result=TestFunc t("This is a string")
response.write( "<BR>result ==> " & result)
End Sub
</script>
</body>
</html>

I've got this error:

Server Error in '/' Application.


--------------------------------------------------------------------------

--
----

Compilation Error
Description: An error occurred during the compilation of a resource
required
to service this request. Please review the following specific error
details
and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'TestFunct' is not declared.

Source Error:
Line 18: Sub Page_Load(s As Object, e As EventArgs)
Line 19:
Line 20: Dim result=TestFunc t("This is a string")
Line 21: response.write( "<BR>Result ==> " & Result)
Line 22:
I have a single .ASPX file and I don't use Visual studio. NET in this
case.
Can I do that ?

Thanks in advance.


Nov 19 '05 #5
Hi Kevin,

This article is what you need when using asp.net 1.1

http://aspnet.4guysfromrolla.com/articles/122403-1.aspx

It gest even simpler if you use asp.net v2. In this cas just drop the class
file in the App_Code directory and you can call them everywhere.

Let me know if you have any more questions...

Cheers,
Tom Pester
You're not thinking fourth-dimensionally! (- Back to the Future)

Actually, you're not thinking Object-Orientationally .

ASP.Net is object-oriented, and you'd better get acquainted with it,
or you'll be visiting here almost daily, and writing crappy code until
you do. Let me elaborate, if you will:

Files are source code. Your application doesn't have files. It has
classes. A file defines a class, but IS not a class. A class is a data
type, and exists in the context of a running application. So, when
you're talking about how your application works, the first thing you
need to do is think about classes, not files. A file can contain one
or MORE class definitions, and you need to get acquainted with classes
to be successful with .Net.

Classes are very important in .Net programming; Objects are made from
classes, and classes provide encapsulation. Object-oriented
programming can get pretty darned complex, and encapsulation can save
you a lot of grief, by hiding those things which need hiding from
those things that don't need them.

If you have a file with a bunch of Subs and Functions in it, you need
to create a class with Subs and Functions in it. These Subs and
Functions can be Shared (meaning that they are singleton objects that
don't require a class instance to operate), or they can be Instance
(meaning that an instance of the class containing them must be created
in order to use them). The advantage to Shared data and process is
that it doesn't require a class instance, and is, in essence "global,"
available to the entire application. This is also the disadvantage of
Shared data and process. Anything can get to it, and change it, and in
a multi-threaded app (unlike VB 6, .net is multi-threaded), this can
cause all sorts of problems. Unless you're familiar with the issues, I
would stick with classes that require instantiation. Instantiation is
the process of creating a copy (instance) of a class that is limited
in its scope (availability), and is thread-safe.

Once you create an instance of a class, you can access any Public or
Friend (Friend is more protected than Public, but you shouldn't run
into issues right away) members from any other class that references
the instance.

From your question, and the code you posted, I can see that you
require a good bit more education and practice. I would recommend the
.Net SDK, a free download from:

http://www.microsoft.com/downloads/d...=9B3A2CA6-3647
-4070-9F41-A333C6B9181D&di splaylang=en

It is extremely important to know the difference between ASP and
ASP.Net, between VBScript or VB 6, and VB.Net. The first are
procedural, single-threaded, and easy to use for small applications.
.Net is object-oriented, multi-threaded, and easy to use once you
spend a great deal of time studying it, but incredibly hard to use if
you don't.

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"bienwell" <bi******@hotma il.com> wrote in message
news:O7******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I have a question about file included in ASP.NET. I have a file
that includes all the Sub functions (e.g FileFunct.vb). One of the
functions in this file is :

Sub TestFunct(ByVal strInput As String)
return (strInput & " test")
End Sub
I'd like to call this function in FileFunct.vb from another .ASPX
file like this :

<%@ import Namespace="Syst em" %>
<%@ import Namespace="Syst em.Data" %>
<html>
<head>
<title>Test page</title>
</head>
<body>
<script runat="server" language="VB" scr="FileFunct. vb" >
Sub Page_Load(s As Object, e As EventArgs)
Dim result=TestFunc t("This is a string")
response.write( "<BR>result ==> " & result)
End Sub
</script>
</body>
</html>
I've got this error:

Server Error in '/' Application.
---------------------------------------------------------------------
------- ----

Compilation Error
Description: An error occurred during the compilation of a resource
required
to service this request. Please review the following specific error
details
and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'TestFunct' is not declared.

Source Error:

Line 18: Sub Page_Load(s As Object, e As EventArgs)
Line 19:
Line 20: Dim result=TestFunc t("This is a string")
Line 21: response.write( "<BR>Result ==> " & Result)
Line 22:
I have a single .ASPX file and I don't use Visual studio. NET in this
case.
Can I do that ?
Thanks in advance.

Nov 19 '05 #6
Sorry dude, it may be all YOU need, but my requirements go a good bit
farther.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"tom pester" <To************ ********@pandor a.be> wrote in message
news:a1******** *************** ***@news.micros oft.com...
Hi Kevin,

This article is what you need when using asp.net 1.1

http://aspnet.4guysfromrolla.com/articles/122403-1.aspx

It gest even simpler if you use asp.net v2. In this cas just drop the
class file in the App_Code directory and you can call them everywhere.

Let me know if you have any more questions...

Cheers,
Tom Pester
You're not thinking fourth-dimensionally! (- Back to the Future)

Actually, you're not thinking Object-Orientationally .

ASP.Net is object-oriented, and you'd better get acquainted with it,
or you'll be visiting here almost daily, and writing crappy code until
you do. Let me elaborate, if you will:

Files are source code. Your application doesn't have files. It has
classes. A file defines a class, but IS not a class. A class is a data
type, and exists in the context of a running application. So, when
you're talking about how your application works, the first thing you
need to do is think about classes, not files. A file can contain one
or MORE class definitions, and you need to get acquainted with classes
to be successful with .Net.

Classes are very important in .Net programming; Objects are made from
classes, and classes provide encapsulation. Object-oriented
programming can get pretty darned complex, and encapsulation can save
you a lot of grief, by hiding those things which need hiding from
those things that don't need them.

If you have a file with a bunch of Subs and Functions in it, you need
to create a class with Subs and Functions in it. These Subs and
Functions can be Shared (meaning that they are singleton objects that
don't require a class instance to operate), or they can be Instance
(meaning that an instance of the class containing them must be created
in order to use them). The advantage to Shared data and process is
that it doesn't require a class instance, and is, in essence "global,"
available to the entire application. This is also the disadvantage of
Shared data and process. Anything can get to it, and change it, and in
a multi-threaded app (unlike VB 6, .net is multi-threaded), this can
cause all sorts of problems. Unless you're familiar with the issues, I
would stick with classes that require instantiation. Instantiation is
the process of creating a copy (instance) of a class that is limited
in its scope (availability), and is thread-safe.

Once you create an instance of a class, you can access any Public or
Friend (Friend is more protected than Public, but you shouldn't run
into issues right away) members from any other class that references
the instance.

From your question, and the code you posted, I can see that you
require a good bit more education and practice. I would recommend the
.Net SDK, a free download from:

http://www.microsoft.com/downloads/d...=9B3A2CA6-3647
-4070-9F41-A333C6B9181D&di splaylang=en

It is extremely important to know the difference between ASP and
ASP.Net, between VBScript or VB 6, and VB.Net. The first are
procedural, single-threaded, and easy to use for small applications.
.Net is object-oriented, multi-threaded, and easy to use once you
spend a great deal of time studying it, but incredibly hard to use if
you don't.

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"bienwell" <bi******@hotma il.com> wrote in message
news:O7******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I have a question about file included in ASP.NET. I have a file
that includes all the Sub functions (e.g FileFunct.vb). One of the
functions in this file is :

Sub TestFunct(ByVal strInput As String)
return (strInput & " test")
End Sub
I'd like to call this function in FileFunct.vb from another .ASPX
file like this :

<%@ import Namespace="Syst em" %>
<%@ import Namespace="Syst em.Data" %>
<html>
<head>
<title>Test page</title>
</head>
<body>
<script runat="server" language="VB" scr="FileFunct. vb" >
Sub Page_Load(s As Object, e As EventArgs)
Dim result=TestFunc t("This is a string")
response.write( "<BR>result ==> " & result)
End Sub
</script>
</body>
</html>
I've got this error:

Server Error in '/' Application.
---------------------------------------------------------------------
------- ----

Compilation Error
Description: An error occurred during the compilation of a resource
required
to service this request. Please review the following specific error
details
and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'TestFunct' is not declared.

Source Error:

Line 18: Sub Page_Load(s As Object, e As EventArgs)
Line 19:
Line 20: Dim result=TestFunc t("This is a string")
Line 21: response.write( "<BR>Result ==> " & Result)
Line 22:
I have a single .ASPX file and I don't use Visual studio. NET in this
case.
Can I do that ?
Thanks in advance.


Nov 19 '05 #7
I'm afraid anything but Best Practices is outside of my purview.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"bienwell" <bi******@hotma il.com> wrote in message
news:eu******** ******@tk2msftn gp13.phx.gbl...
Kevin,

Last time I put all the files in my application (project name) using
Visual
Studio.NET, declared a class (AClass) which has some functions, and saved
them in a file (.vb file). My program worked fine when I called the
function
from my other .vb files (AClass.Functio n1, ...). My application was
Object-Oriented well development. Now, I'd like to try another way :
creating .ASPX file that contains VB.NET script, HTML and call one
function
from another .vb file without using Visual Studio.NET. Can I do that and
How
? It's my question.


"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:u7******** ******@TK2MSFTN GP15.phx.gbl...
You're not thinking fourth-dimensionally! (- Back to the Future)

Actually, you're not thinking Object-Orientationally .

ASP.Net is object-oriented, and you'd better get acquainted with it, or
you'll be visiting here almost daily, and writing crappy code until you

do.
Let me elaborate, if you will:

Files are source code. Your application doesn't have files. It has

classes.
A file defines a class, but IS not a class. A class is a data type, and
exists in the context of a running application. So, when you're talking
about how your application works, the first thing you need to do is think
about classes, not files. A file can contain one or MORE class

definitions,
and you need to get acquainted with classes to be successful with .Net.

Classes are very important in .Net programming; Objects are made from
classes, and classes provide encapsulation. Object-oriented programming

can
get pretty darned complex, and encapsulation can save you a lot of grief,

by
hiding those things which need hiding from those things that don't need
them.

If you have a file with a bunch of Subs and Functions in it, you need to
create a class with Subs and Functions in it. These Subs and Functions
can
be Shared (meaning that they are singleton objects that don't require a
class instance to operate), or they can be Instance (meaning that an
instance of the class containing them must be created in order to use

them).
The advantage to Shared data and process is that it doesn't require a

class
instance, and is, in essence "global," available to the entire

application.
This is also the disadvantage of Shared data and process. Anything can
get
to it, and change it, and in a multi-threaded app (unlike VB 6, .net is
multi-threaded), this can cause all sorts of problems. Unless you're
familiar with the issues, I would stick with classes that require
instantiation. Instantiation is the process of creating a copy (instance)

of
a class that is limited in its scope (availability), and is thread-safe.

Once you create an instance of a class, you can access any Public or

Friend
(Friend is more protected than Public, but you shouldn't run into issues
right away) members from any other class that references the instance.

From your question, and the code you posted, I can see that you require a
good bit more education and practice. I would recommend the .Net SDK, a

free
download from:

http://www.microsoft.com/downloads/d...displaylang=en

It is extremely important to know the difference between ASP and ASP.Net,
between VBScript or VB 6, and VB.Net. The first are procedural,
single-threaded, and easy to use for small applications. .Net is
object-oriented, multi-threaded, and easy to use once you spend a great

deal
of time studying it, but incredibly hard to use if you don't.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"bienwell" <bi******@hotma il.com> wrote in message
news:O7******** ******@TK2MSFTN GP10.phx.gbl...
> Hi,
>
> I have a question about file included in ASP.NET. I have a file that
> includes all the Sub functions (e.g FileFunct.vb). One of the functions > in this file is :
>
> Sub TestFunct(ByVal strInput As String)
> return (strInput & " test")
> End Sub
>
>
> I'd like to call this function in FileFunct.vb from another .ASPX
> file
> like this :
>
> <%@ import Namespace="Syst em" %>
> <%@ import Namespace="Syst em.Data" %>
>
> <html>
> <head>
> <title>Test page</title>
> </head>
>
> <body>
> <script runat="server" language="VB" scr="FileFunct. vb" >
>
> Sub Page_Load(s As Object, e As EventArgs)
> Dim result=TestFunc t("This is a string")
> response.write( "<BR>result ==> " & result)
> End Sub
> </script>
> </body>
> </html>
>
> I've got this error:
>
> Server Error in '/' Application.


--------------------------------------------------------------------------

--
> ----
>
> Compilation Error
> Description: An error occurred during the compilation of a resource
> required
> to service this request. Please review the following specific error
> details
> and modify your source code appropriately.
>
> Compiler Error Message: BC30451: Name 'TestFunct' is not declared.
>
> Source Error:
>
>
> Line 18: Sub Page_Load(s As Object, e As EventArgs)
> Line 19:
> Line 20: Dim result=TestFunc t("This is a string")
> Line 21: response.write( "<BR>Result ==> " & Result)
> Line 22:
>
>
> I have a single .ASPX file and I don't use Visual studio. NET in this
> case.
> Can I do that ?
>
> Thanks in advance.
>
>



Nov 19 '05 #8
Thanks, Tom. I did try it last time and it worked when I put all the files
in an application using Visual Studio.NET. My requirement now is to create
a single .ASPX file containing VB.NET language, JavaScript language and
HTML, and call a function from this .ASPX file without using Visual
Studio.NET to create an application.

..
"tom pester" <To************ ********@pandor a.be> wrote in message
news:a1******** *************** ***@news.micros oft.com...
Hi Kevin,

This article is what you need when using asp.net 1.1

http://aspnet.4guysfromrolla.com/articles/122403-1.aspx

It gest even simpler if you use asp.net v2. In this cas just drop the class file in the App_Code directory and you can call them everywhere.

Let me know if you have any more questions...

Cheers,
Tom Pester
You're not thinking fourth-dimensionally! (- Back to the Future)

Actually, you're not thinking Object-Orientationally .

ASP.Net is object-oriented, and you'd better get acquainted with it,
or you'll be visiting here almost daily, and writing crappy code until
you do. Let me elaborate, if you will:

Files are source code. Your application doesn't have files. It has
classes. A file defines a class, but IS not a class. A class is a data
type, and exists in the context of a running application. So, when
you're talking about how your application works, the first thing you
need to do is think about classes, not files. A file can contain one
or MORE class definitions, and you need to get acquainted with classes
to be successful with .Net.

Classes are very important in .Net programming; Objects are made from
classes, and classes provide encapsulation. Object-oriented
programming can get pretty darned complex, and encapsulation can save
you a lot of grief, by hiding those things which need hiding from
those things that don't need them.

If you have a file with a bunch of Subs and Functions in it, you need
to create a class with Subs and Functions in it. These Subs and
Functions can be Shared (meaning that they are singleton objects that
don't require a class instance to operate), or they can be Instance
(meaning that an instance of the class containing them must be created
in order to use them). The advantage to Shared data and process is
that it doesn't require a class instance, and is, in essence "global,"
available to the entire application. This is also the disadvantage of
Shared data and process. Anything can get to it, and change it, and in
a multi-threaded app (unlike VB 6, .net is multi-threaded), this can
cause all sorts of problems. Unless you're familiar with the issues, I
would stick with classes that require instantiation. Instantiation is
the process of creating a copy (instance) of a class that is limited
in its scope (availability), and is thread-safe.

Once you create an instance of a class, you can access any Public or
Friend (Friend is more protected than Public, but you shouldn't run
into issues right away) members from any other class that references
the instance.

From your question, and the code you posted, I can see that you
require a good bit more education and practice. I would recommend the
.Net SDK, a free download from:

http://www.microsoft.com/downloads/d...=9B3A2CA6-3647
-4070-9F41-A333C6B9181D&di splaylang=en

It is extremely important to know the difference between ASP and
ASP.Net, between VBScript or VB 6, and VB.Net. The first are
procedural, single-threaded, and easy to use for small applications.
.Net is object-oriented, multi-threaded, and easy to use once you
spend a great deal of time studying it, but incredibly hard to use if
you don't.

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"bienwell" <bi******@hotma il.com> wrote in message
news:O7******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I have a question about file included in ASP.NET. I have a file
that includes all the Sub functions (e.g FileFunct.vb). One of the
functions in this file is :

Sub TestFunct(ByVal strInput As String)
return (strInput & " test")
End Sub
I'd like to call this function in FileFunct.vb from another .ASPX
file like this :

<%@ import Namespace="Syst em" %>
<%@ import Namespace="Syst em.Data" %>
<html>
<head>
<title>Test page</title>
</head>
<body>
<script runat="server" language="VB" scr="FileFunct. vb" >
Sub Page_Load(s As Object, e As EventArgs)
Dim result=TestFunc t("This is a string")
response.write( "<BR>result ==> " & result)
End Sub
</script>
</body>
</html>
I've got this error:

Server Error in '/' Application.
---------------------------------------------------------------------
------- ----

Compilation Error
Description: An error occurred during the compilation of a resource
required
to service this request. Please review the following specific error
details
and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'TestFunct' is not declared.

Source Error:

Line 18: Sub Page_Load(s As Object, e As EventArgs)
Line 19:
Line 20: Dim result=TestFunc t("This is a string")
Line 21: response.write( "<BR>Result ==> " & Result)
Line 22:
I have a single .ASPX file and I don't use Visual studio. NET in this
case.
Can I do that ?
Thanks in advance.


Nov 19 '05 #9

If you use asp.net version 1 you need to compile the class file with the
command line compiler and put the created dll in the bin directory.
Check out this 2 part article :

http://www.4guysfromrolla.com/webtech/112101-1.2.shtml

If you use asp.net version 2 just drop the class files in the App_Code and
that's it. The engine will compile all files in this dir and make it available
to the whole app without us to worry about compilation

Let me know if it helped you or not...

Cheers,
Tom Pester
Thanks, Tom. I did try it last time and it worked when I put all the
files in an application using Visual Studio.NET. My requirement now
is to create a single .ASPX file containing VB.NET language,
JavaScript language and HTML, and call a function from this .ASPX
file without using Visual Studio.NET to create an application.

.
"tom pester" <To************ ********@pandor a.be> wrote in message
news:a1******** *************** ***@news.micros oft.com...
Hi Kevin,

This article is what you need when using asp.net 1.1

http://aspnet.4guysfromrolla.com/articles/122403-1.aspx

It gest even simpler if you use asp.net v2. In this cas just drop the

class
file in the App_Code directory and you can call them everywhere.

Let me know if you have any more questions...

Cheers,
Tom Pester
You're not thinking fourth-dimensionally! (- Back to the Future)

Actually, you're not thinking Object-Orientationally .

ASP.Net is object-oriented, and you'd better get acquainted with it,
or you'll be visiting here almost daily, and writing crappy code
until you do. Let me elaborate, if you will:

Files are source code. Your application doesn't have files. It has
classes. A file defines a class, but IS not a class. A class is a
data type, and exists in the context of a running application. So,
when you're talking about how your application works, the first
thing you need to do is think about classes, not files. A file can
contain one or MORE class definitions, and you need to get
acquainted with classes to be successful with .Net.

Classes are very important in .Net programming; Objects are made
from classes, and classes provide encapsulation. Object-oriented
programming can get pretty darned complex, and encapsulation can
save you a lot of grief, by hiding those things which need hiding
from those things that don't need them.

If you have a file with a bunch of Subs and Functions in it, you
need to create a class with Subs and Functions in it. These Subs and
Functions can be Shared (meaning that they are singleton objects
that don't require a class instance to operate), or they can be
Instance (meaning that an instance of the class containing them must
be created in order to use them). The advantage to Shared data and
process is that it doesn't require a class instance, and is, in
essence "global," available to the entire application. This is also
the disadvantage of Shared data and process. Anything can get to it,
and change it, and in a multi-threaded app (unlike VB 6, .net is
multi-threaded), this can cause all sorts of problems. Unless you're
familiar with the issues, I would stick with classes that require
instantiation. Instantiation is the process of creating a copy
(instance) of a class that is limited in its scope (availability),
and is thread-safe.

Once you create an instance of a class, you can access any Public or
Friend (Friend is more protected than Public, but you shouldn't run
into issues right away) members from any other class that references
the instance.

From your question, and the code you posted, I can see that you
require a good bit more education and practice. I would recommend
the .Net SDK, a free download from:

http://www.microsoft.com/downloads/d...Id=9B3A2CA6-36
47 -4070-9F41-A333C6B9181D&di splaylang=en

It is extremely important to know the difference between ASP and
ASP.Net, between VBScript or VB 6, and VB.Net. The first are
procedural, single-threaded, and easy to use for small applications.
.Net is object-oriented, multi-threaded, and easy to use once you
spend a great deal of time studying it, but incredibly hard to use
if you don't.

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"bienwell" <bi******@hotma il.com> wrote in message
news:O7******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I have a question about file included in ASP.NET. I have a file
that includes all the Sub functions (e.g FileFunct.vb). One of
the functions in this file is :

Sub TestFunct(ByVal strInput As String)
return (strInput & " test")
End Sub
I'd like to call this function in FileFunct.vb from another .ASPX
file like this :
<%@ import Namespace="Syst em" %>
<%@ import Namespace="Syst em.Data" %>
<html>
<head>
<title>Test page</title>
</head>
<body>
<script runat="server" language="VB" scr="FileFunct. vb" >
Sub Page_Load(s As Object, e As EventArgs)
Dim result=TestFunc t("This is a string")
response.write( "<BR>result ==> " & result)
End Sub
</script>
</body>
</html>
I've got this error:
Server Error in '/' Application.
-------------------------------------------------------------------
-- ------- ----

Compilation Error
Description: An error occurred during the compilation of a resource
required
to service this request. Please review the following specific error
details
and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'TestFunct' is not declared.
Source Error:

Line 18: Sub Page_Load(s As Object, e As EventArgs)
Line 19:
Line 20: Dim result=TestFunc t("This is a string")
Line 21: response.write( "<BR>Result ==> " & Result)
Line 22:
I have a single .ASPX file and I don't use Visual studio. NET in
this
case.
Can I do that ?
Thanks in advance.

Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3035
by: moondaddy | last post by:
I'm using vb.net and have an aspx page where I want to call a function in the code behind to do something on the backend and I want to call this function from a jscript function in the aspx page. Furthermore I know there will be a postback involved but the state of the page will not change at all so I would like it to be as efficient as...
7
2675
by: Tiraman | last post by:
Hi , I have 3 files , middle.aspx file include the header.aspx and footer.aspx files . in each of the include files there is a function and from some reason the call to the Footer() function from the Header.aspx file works fine But The Call From The Footer.aspx file to the Header() function doesn't work bcz of some Compiler Error Message:...
6
2386
by: Olivier Matrot | last post by:
Hello, This has probably been asked several times, but It must be clarified for me. I would like to know why sometimes during a postback Page_Load is called after the function marked for postback. Here's the deal : From now on, I set CurrentThread.CurrentCulture only during PageLoad. so date and currency format is incorrect if page load is...
4
3899
by: abcd | last post by:
I am novice asp.net programmer. I have xyz.js file which has resuable functions. I have asp.net form abcd.aspx and the code behind file abcd.aspx.cs, I want to put a 'Help' button when clicked it will open a window and open the required file for me. I am have issues 1.I tried calling my xyz.js function i.e. ShowHelp in the call like...
4
59899
by: verci | last post by:
Hi guys, I'm running asp.net 2.0. Does anyone know how to fire or call a javascript function from inside my (VB.aspx) code without assigning it to a control attribute? thank you
5
9846
by: moni | last post by:
Hi.. I am trying to use javascript for google maps display. If I call the javascript function from my aspx file I use: <input type="text" id="addresstext" value="Huntington Avenue, Boston, MA" name="yourName" style="width: 287px" />
6
5893
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with or without parms. I know that any function that is passed to Eval() must be declared Public. It can be a Sub or Function, as long as it's Public. I...
4
1672
by: Ajvan | last post by:
Hi everybody, I have one problem, and I hope some of you guys can help me with this. I`m working in C# (Visual Studio 2005)...writing simple web site . I place grid on Default.aspx and put one textbox in it. On the other side, on Default.aspx.cs page I write simple method which dynamicly generate Radio Button on page..(code bellow): ...
0
1761
by: sancti | last post by:
hi , I am developing a webpage.I want to call a function from .aspx.cs file to .aspx file. i.e I have to pass the parameter from .aspx.cs file to the function which is in .aspx file.How can i do this? Thanks in advance
0
7539
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7819
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5165
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3589
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2030
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1149
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
858
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.