473,769 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use a class in an aspx file?

Jan
Hi,

I defined a function like this:
Public Function myfunction(ByVa l myvar As Object) As String
...
Return xyz
End Function

in aspx file, i use it like this:

<asp:Literal ID="lit" runat="server" Text='<%# myfunction(Eval ("myfield"))
%>' />
Now i defined a class with the same function like this:

Public Class descr
Public Shared Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class
My question is: how to use that class in the aspx file?

Thanks
Jan
Mar 7 '07 #1
11 1604
are you talking about clientside?

ASP.net doesn't support clientside script

sorry

On Mar 7, 12:36 pm, "Jan" <cbcbc@xcvxwrot e:
Hi,

I defined a function like this:
Public Function myfunction(ByVa l myvar As Object) As String
...
Return xyz
End Function

in aspx file, i use it like this:

<asp:Literal ID="lit" runat="server" Text='<%# myfunction(Eval ("myfield"))
%>' />

Now i defined a class with the same function like this:

Public Class descr
Public Shared Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class

My question is: how to use that class in the aspx file?

Thanks
Jan

Mar 7 '07 #2
Jan wrote:
Hi,

I defined a function like this:
Public Function myfunction(ByVa l myvar As Object) As String
...
Return xyz
End Function

in aspx file, i use it like this:

<asp:Literal ID="lit" runat="server" Text='<%# myfunction(Eval ("myfield"))
%>' />
Now i defined a class with the same function like this:

Public Class descr
Public Shared Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class
My question is: how to use that class in the aspx file?

Thanks
Jan
As the method is static (Shared in VB), you access it by specifying the
class name and the method:

<%# descr.myfunctio n(Eval("myfield ")) %>

--
Göran Andersson
_____
http://www.guffa.com
Mar 8 '07 #3
Jan,

Be aware that you are creating a dangerous module with your code.
A shared class as you made it, is in VB nothing more than a module, which in
this case is static in memory as all modules are. .

An application in ASP.Net belongs to all clients, therefore the module as
you make it can be used as a conainer for constants. Not for data belonging
to one client. For that you need a real class.

Class TheClassIWantTo Use
Public Sub New
'this is the constructor
End Sub
Public function CountTheWhateve r(byval Counter as integer)
return Counter + 1
end sub

To use you say
public sub WhatIWantToDo as TheClassIWantTo Use

You can than use it as.
counter = WhatIWantToDo.C ountTheWhatever (1)

I hope this gives an idea

Cor
"Jan" <cbcbc@xcvxschr eef in bericht
news:OQ******** ******@TK2MSFTN GP05.phx.gbl...
Hi,

I defined a function like this:
Public Function myfunction(ByVa l myvar As Object) As String
...
Return xyz
End Function

in aspx file, i use it like this:

<asp:Literal ID="lit" runat="server" Text='<%# myfunction(Eval ("myfield"))
%>' />
Now i defined a class with the same function like this:

Public Class descr
Public Shared Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class
My question is: how to use that class in the aspx file?

Thanks
Jan

Mar 8 '07 #4
Jan
Thanks to both

"Cor Ligthert [MVP]" <no************ @planet.nlschre ef in bericht
news:uB******** ******@TK2MSFTN GP03.phx.gbl...
Jan,

Be aware that you are creating a dangerous module with your code.
A shared class as you made it, is in VB nothing more than a module, which
in this case is static in memory as all modules are. .

An application in ASP.Net belongs to all clients, therefore the module as
you make it can be used as a conainer for constants. Not for data
belonging to one client. For that you need a real class.

Class TheClassIWantTo Use
Public Sub New
'this is the constructor
End Sub
Public function CountTheWhateve r(byval Counter as integer)
return Counter + 1
end sub

To use you say
public sub WhatIWantToDo as TheClassIWantTo Use

You can than use it as.
counter = WhatIWantToDo.C ountTheWhatever (1)

I hope this gives an idea

Cor
"Jan" <cbcbc@xcvxschr eef in bericht
news:OQ******** ******@TK2MSFTN GP05.phx.gbl...
>Hi,

I defined a function like this:
Public Function myfunction(ByVa l myvar As Object) As String
...
Return xyz
End Function

in aspx file, i use it like this:

<asp:Literal ID="lit" runat="server" Text='<%#
myfunction(Eva l("myfield")) %>' />
Now i defined a class with the same function like this:

Public Class descr
Public Shared Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class
My question is: how to use that class in the aspx file?

Thanks
Jan


Mar 8 '07 #5
Jan
Cor or Goran,

After your explanation about the dangereous Shared, i tried the same with a
normal class, but this doesn't work.
So i have the same question: how to use a normal class in an aspx file?

in aspx file, i use a (non-class) function like this:

<asp:Literal ID="lit" runat="server" Text='<%# myfunction(Eval ("myfield"))
%>' />

i tried this: <%# descr.myfunctio n(Eval("myfield ")) %but of course, it
fails ...

my class is now:
---------------
Public Class descr
Public Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class


"Cor Ligthert [MVP]" <no************ @planet.nlschre ef in bericht
news:uB******** ******@TK2MSFTN GP03.phx.gbl...
Jan,

Be aware that you are creating a dangerous module with your code.
A shared class as you made it, is in VB nothing more than a module, which
in this case is static in memory as all modules are. .

An application in ASP.Net belongs to all clients, therefore the module as
you make it can be used as a conainer for constants. Not for data
belonging to one client. For that you need a real class.

Class TheClassIWantTo Use
Public Sub New
'this is the constructor
End Sub
Public function CountTheWhateve r(byval Counter as integer)
return Counter + 1
end sub

To use you say
public sub WhatIWantToDo as TheClassIWantTo Use

You can than use it as.
counter = WhatIWantToDo.C ountTheWhatever (1)

I hope this gives an idea

Cor
"Jan" <cbcbc@xcvxschr eef in bericht
news:OQ******** ******@TK2MSFTN GP05.phx.gbl...
>Hi,

I defined a function like this:
Public Function myfunction(ByVa l myvar As Object) As String
...
Return xyz
End Function

in aspx file, i use it like this:

<asp:Literal ID="lit" runat="server" Text='<%#
myfunction(Eva l("myfield")) %>' />
Now i defined a class with the same function like this:

Public Class descr
Public Shared Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class
My question is: how to use that class in the aspx file?

Thanks
Jan


Mar 8 '07 #6
There is nothing dangerous with a shared method.

If you would use shared variables in the method, that would be something
different, but that would be dangerus because of the shared variable,
not at all because it's done in a shared method.

There are a lot of shared methods that you use all the time, like
Int32.Parse, DateTime.Now, String.Concat or Math.Round. There is nothing
dangerous about them.

Jan wrote:
Cor or Goran,

After your explanation about the dangereous Shared, i tried the same with a
normal class, but this doesn't work.
So i have the same question: how to use a normal class in an aspx file?

in aspx file, i use a (non-class) function like this:

<asp:Literal ID="lit" runat="server" Text='<%# myfunction(Eval ("myfield"))
%>' />

i tried this: <%# descr.myfunctio n(Eval("myfield ")) %but of course, it
fails ...

my class is now:
---------------
Public Class descr
Public Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class


"Cor Ligthert [MVP]" <no************ @planet.nlschre ef in bericht
news:uB******** ******@TK2MSFTN GP03.phx.gbl...
>Jan,

Be aware that you are creating a dangerous module with your code.
A shared class as you made it, is in VB nothing more than a module, which
in this case is static in memory as all modules are. .

An application in ASP.Net belongs to all clients, therefore the module as
you make it can be used as a conainer for constants. Not for data
belonging to one client. For that you need a real class.

Class TheClassIWantTo Use
Public Sub New
'this is the constructor
End Sub
Public function CountTheWhateve r(byval Counter as integer)
return Counter + 1
end sub

To use you say
public sub WhatIWantToDo as TheClassIWantTo Use

You can than use it as.
counter = WhatIWantToDo.C ountTheWhatever (1)

I hope this gives an idea

Cor
"Jan" <cbcbc@xcvxschr eef in bericht
news:OQ******* *******@TK2MSFT NGP05.phx.gbl.. .
>>Hi,

I defined a function like this:
Public Function myfunction(ByVa l myvar As Object) As String
...
Return xyz
End Function

in aspx file, i use it like this:

<asp:Litera l ID="lit" runat="server" Text='<%#
myfunction(Ev al("myfield")) %>' />
Now i defined a class with the same function like this:

Public Class descr
Public Shared Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class
My question is: how to use that class in the aspx file?

Thanks
Jan


--
Göran Andersson
_____
http://www.guffa.com
Mar 8 '07 #7
Goran,

I had not the idea that we were talking about a shared methods. As well not
to a static variable.

We were talking about a shared Class were I especially wrote about module.

If you are used to the behaviour of a Shared Class/Module in a windowsform
situation than a Shared Class/Module is dangerous to use in ASPX.

I know at least one person who was in past writting the same as you and is
now warning every time for that.

Cor

"Göran Andersson" <gu***@guffa.co mschreef in bericht
news:OM******** ******@TK2MSFTN GP02.phx.gbl...
There is nothing dangerous with a shared method.

If you would use shared variables in the method, that would be something
different, but that would be dangerus because of the shared variable, not
at all because it's done in a shared method.

There are a lot of shared methods that you use all the time, like
Int32.Parse, DateTime.Now, String.Concat or Math.Round. There is nothing
dangerous about them.

Jan wrote:
>Cor or Goran,

After your explanation about the dangereous Shared, i tried the same with
a normal class, but this doesn't work.
So i have the same question: how to use a normal class in an aspx file?

in aspx file, i use a (non-class) function like this:

<asp:Literal ID="lit" runat="server" Text='<%#
myfunction(Eva l("myfield")) %>' />

i tried this: <%# descr.myfunctio n(Eval("myfield ")) %but of course, it
fails ...

my class is now:
---------------
Public Class descr
Public Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class


"Cor Ligthert [MVP]" <no************ @planet.nlschre ef in bericht
news:uB******* *******@TK2MSFT NGP03.phx.gbl.. .
>>Jan,

Be aware that you are creating a dangerous module with your code.
A shared class as you made it, is in VB nothing more than a module,
which in this case is static in memory as all modules are. .

An application in ASP.Net belongs to all clients, therefore the module
as you make it can be used as a conainer for constants. Not for data
belonging to one client. For that you need a real class.

Class TheClassIWantTo Use
Public Sub New
'this is the constructor
End Sub
Public function CountTheWhateve r(byval Counter as integer)
return Counter + 1
end sub

To use you say
public sub WhatIWantToDo as TheClassIWantTo Use

You can than use it as.
counter = WhatIWantToDo.C ountTheWhatever (1)

I hope this gives an idea

Cor
"Jan" <cbcbc@xcvxschr eef in bericht
news:OQ****** ********@TK2MSF TNGP05.phx.gbl. ..
Hi,

I defined a function like this:
Public Function myfunction(ByVa l myvar As Object) As String
...
Return xyz
End Function

in aspx file, i use it like this:

<asp:Liter al ID="lit" runat="server" Text='<%#
myfunction(E val("myfield")) %>' />
Now i defined a class with the same function like this:

Public Class descr
Public Shared Function myfunction(ByVa l myvar As Object) As
String
.....
Return xyz
End Function
End Class
My question is: how to use that class in the aspx file?

Thanks
Jan




--
Göran Andersson
_____
http://www.guffa.com

Mar 9 '07 #8
Jan,

At least you have to instance it (construct it), in my message I forgot the
"New" word sorry for that

Your code will than be
dim mydescr as new descr.

Cor

"Jan" <uu*****@fff.ty schreef in bericht
news:%2******** *********@TK2MS FTNGP06.phx.gbl ...
Cor or Goran,

After your explanation about the dangereous Shared, i tried the same with
a normal class, but this doesn't work.
So i have the same question: how to use a normal class in an aspx file?

in aspx file, i use a (non-class) function like this:

<asp:Literal ID="lit" runat="server" Text='<%# myfunction(Eval ("myfield"))
%>' />

i tried this: <%# descr.myfunctio n(Eval("myfield ")) %but of course, it
fails ...

my class is now:
---------------
Public Class descr
Public Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class


"Cor Ligthert [MVP]" <no************ @planet.nlschre ef in bericht
news:uB******** ******@TK2MSFTN GP03.phx.gbl...
>Jan,

Be aware that you are creating a dangerous module with your code.
A shared class as you made it, is in VB nothing more than a module, which
in this case is static in memory as all modules are. .

An application in ASP.Net belongs to all clients, therefore the module as
you make it can be used as a conainer for constants. Not for data
belonging to one client. For that you need a real class.

Class TheClassIWantTo Use
Public Sub New
'this is the constructor
End Sub
Public function CountTheWhateve r(byval Counter as integer)
return Counter + 1
end sub

To use you say
public sub WhatIWantToDo as TheClassIWantTo Use

You can than use it as.
counter = WhatIWantToDo.C ountTheWhatever (1)

I hope this gives an idea

Cor
"Jan" <cbcbc@xcvxschr eef in bericht
news:OQ******* *******@TK2MSFT NGP05.phx.gbl.. .
>>Hi,

I defined a function like this:
Public Function myfunction(ByVa l myvar As Object) As String
...
Return xyz
End Function

in aspx file, i use it like this:

<asp:Litera l ID="lit" runat="server" Text='<%#
myfunction(Ev al("myfield")) %>' />
Now i defined a class with the same function like this:

Public Class descr
Public Shared Function myfunction(ByVa l myvar As Object) As
String
.....
Return xyz
End Function
End Class
My question is: how to use that class in the aspx file?

Thanks
Jan



Mar 9 '07 #9
Jan
Thanks.
"Cor Ligthert [MVP]" <no************ @planet.nlschre ef in bericht
news:OF******** ******@TK2MSFTN GP06.phx.gbl...
Jan,

At least you have to instance it (construct it), in my message I forgot
the "New" word sorry for that

Your code will than be
dim mydescr as new descr.

Cor

"Jan" <uu*****@fff.ty schreef in bericht
news:%2******** *********@TK2MS FTNGP06.phx.gbl ...
>Cor or Goran,

After your explanation about the dangereous Shared, i tried the same with
a normal class, but this doesn't work.
So i have the same question: how to use a normal class in an aspx file?

in aspx file, i use a (non-class) function like this:

<asp:Literal ID="lit" runat="server" Text='<%#
myfunction(Eva l("myfield")) %>' />

i tried this: <%# descr.myfunctio n(Eval("myfield ")) %but of course, it
fails ...

my class is now:
---------------
Public Class descr
Public Function myfunction(ByVa l myvar As Object) As String
.....
Return xyz
End Function
End Class


"Cor Ligthert [MVP]" <no************ @planet.nlschre ef in bericht
news:uB******* *******@TK2MSFT NGP03.phx.gbl.. .
>>Jan,

Be aware that you are creating a dangerous module with your code.
A shared class as you made it, is in VB nothing more than a module,
which in this case is static in memory as all modules are. .

An application in ASP.Net belongs to all clients, therefore the module
as you make it can be used as a conainer for constants. Not for data
belonging to one client. For that you need a real class.

Class TheClassIWantTo Use
Public Sub New
'this is the constructor
End Sub
Public function CountTheWhateve r(byval Counter as integer)
return Counter + 1
end sub

To use you say
public sub WhatIWantToDo as TheClassIWantTo Use

You can than use it as.
counter = WhatIWantToDo.C ountTheWhatever (1)

I hope this gives an idea

Cor
"Jan" <cbcbc@xcvxschr eef in bericht
news:OQ****** ********@TK2MSF TNGP05.phx.gbl. ..
Hi,

I defined a function like this:
Public Function myfunction(ByVa l myvar As Object) As String
...
Return xyz
End Function

in aspx file, i use it like this:

<asp:Liter al ID="lit" runat="server" Text='<%#
myfunction(E val("myfield")) %>' />
Now i defined a class with the same function like this:

Public Class descr
Public Shared Function myfunction(ByVa l myvar As Object) As
String
.....
Return xyz
End Function
End Class
My question is: how to use that class in the aspx file?

Thanks
Jan



Mar 9 '07 #10

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

Similar topics

4
7023
by: BH | last post by:
I'm looking at the source code of the ASP.NET forum sample application. It has the "code-behind" classes compiled into a separate DLL, totally separated from the aspx/ascx files. Adding the class files alone in VS.NET is straightforward, but is there a way configure VS.NET to add aspx/ascx files alone?
0
951
by: Shail | last post by:
I am using webmatrix tool for developing .aspx files. I have developed one aspx file named test.aspx and one .vb file named test.vb. In my .vb file I have one public class named test and in that class I have one function named testfun which returns string. When I compile my .vb file using command line compiler, it creates a .dll file with the same name of .vb file. I kept this .dll file in bin directory. Now in my test.aspx file I imports this...
4
1580
by: Wayne Wengert | last post by:
I am trying to work through an ASP.NET book and in one example you build a Class and then call a method from that class in an ASPX page. I put the class file ("quote.dll") in the bin directory and then added the aspx page that uses it to the project. When I re-open the project and right click on the aspx file and select the "Add to Project" option I get an error stating: "There is no class file associated with the WebForm 'ShowQuote.aspx'....
2
3377
by: s.hong | last post by:
Hello? On the ASP.NET, I can use the class by import declation on the top of page. <%@ page language="vb" explicit="true" aspcompat="false" debug="true"%> <%@ import namespace="System.Data" %> <%@ import namespace="System.Data.SqlClient" %> It's work well for the compiled class files in /bin folder.
13
1858
by: Duron | last post by:
I created a new folder using VS.NET 2003. Then I created a new web form under that folder, say, \Member\Default.aspx. However, even if I didn't do anything to that page, a run-time error appears when I try to run it -- Can not load class MySite._Default. I am using VB to write codes. Does anyone have any idea why this problem happens? Thanks!
13
2222
by: Bijoy Naick | last post by:
My project contains multiple aspx pages. Many of these pages have code-behind that use several helper functions. Instead of copying each helper function into each aspx page, I am thinking of using a VB Class file to store these. Questions - - How would I "include" this class in each aspx page?
3
1706
by: ABC | last post by:
How to create a web page class for inhert web page using ASP.NET 1.1 and 2.0?
2
2327
by: Hiten | last post by:
Is it possible to have more code behind file but that file will have same class in way of partial class, Default Structure I -------------- Homepage.aspx + Homepage.aspx.cs (this .cs file will have "Homepage" class which is partial)
1
1834
by: Arpan | last post by:
A class file named "SecureDBWS.vb" exsting in C:\Inetpub\wwwroot\ASPX\Business folder has the following code: Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.Services Imports System.Web.Services.Protocols Namespace DBSecuritySettingsWS
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.