|
-
Mar 9th, 2004, 02:58 PM
#1
Thread Starter
New Member
help in calling a function in ASP.Net Project
I have a function call declared in .aspx file that I call from the page_load event and it works fine. But when I move the function call to a Module file, it is not able to find it? The error message that I am getting is function name not declared. How do I call that function from my Page_load event. Please help.
-
Mar 9th, 2004, 05:59 PM
#2
Fanatic Member
I am new to ASP.NET so you will have to bear with me.
Is your function private or public.
I presume is is not a class module.
-
Mar 10th, 2004, 09:27 AM
#3
Thread Starter
New Member
I have created a ASP.net web application project and added a module file in the project. The function is public.
-
Mar 10th, 2004, 03:51 PM
#4
Fanatic Member
I was thinking today and was wondering if you need an imports statement at the beginning of you aspx code.
imports modulename
This is a bit of a stab in the dark.
I understand about classes and can add them so they work, and they are meant to be more difficult than straight modules.
Ah well.
-
Mar 10th, 2004, 04:32 PM
#5
Frenzied Member
If it is a Class file (.vb) then you can just do this
VB Code:
'Functions is the name of your file (Functions.vb)
Dim f As New Functions
Dim strName As String
strName = f.<functionName>(strName)
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Mar 10th, 2004, 04:50 PM
#6
Thread Starter
New Member
Still It does not work. Here is the code I am using.
In the Page_load event of the .aspx file I am using the following code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
' And return the datatable wrapped in a dataview
lbExams.DataSource = DataLoad()
lbExams.DataTextField = "ExamName"
DataBind()
End Sub
DataLoad is a Public function in Exam.vb module file. Here is the code in the Exam.vb file.
Module Exam
Public Function DataLoad() As System.Collections.ICollection
Dim dt As DataTable = New DataTable
Dim dv As DataView
Dim dr As DataRow
' Add two columns to the DataTable
dt.Columns.Add(New DataColumn("ExamNumber", GetType(String)))
dt.Columns.Add(New DataColumn("ExamName", GetType(String)))
' Put some data in
dr = dt.NewRow()
dr(0) = "305"
dr(1) = "Web Applications With VB.NET"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "306"
dr(1) = "Windows Applications With VB.NET"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "310"
dr(1) = "XML With VB.NET"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "315"
dr(1) = "Web Applications With Visual C# .NET"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "316"
dr(1) = "Windows Applications With Visual C# .NET"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "320"
dr(1) = "XML With Visual C# .NET"
dt.Rows.Add(dr)
' And return the datatable wrapped in a dataview
dv = New DataView(dt)
Return dv
End Function
End Module
-
Mar 10th, 2004, 05:04 PM
#7
Frenzied Member
try something like this
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dl As clsDataLoad
lbExams.DataSource = dl.DataLoad()
lbExams.DataTextField = "ExamName"
lbExams.DataBind()
End Sub
Public Class clsDataLoad
'Place function code here
End Class
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Mar 11th, 2004, 05:26 PM
#8
I wonder how many charact
I don't understand your problem. Why not just put this at the top of your web page's .vb file..
VB Code:
Imports NameOfSomeModuleYouMade
And stick this anywhere within that .vb file you need to call it.
VB Code:
Dim myModule As NameOfSomeModuleYouMade
myModule.CallMyFunction
If you need to call it from the front side (Aspx), make a Protected function inside your web page's .vb file that instantiates the class and calls the function.
VB Code:
Protected Sub GoCallMyFunction
Dim myModule As NameOfSomeModuleYouMade
myModule.CallMyFunction
End Sub
-
Mar 16th, 2004, 04:57 AM
#9
Fanatic Member
I am lost for suggestions now.
I created a new web application.
Added a module.
In the module I added a simple function so the module looked like this.
VB Code:
Module Module1
Public Function giveit() As String
Return "something"
End Function
End Module
I added a textbox to the webform and added this code in the page_load event.
When I run the application it worked fine.
Sometimes it helps to go back to basics. But I am not sure in your case.
Did you add a new module to the web application or did you add an existing module you had previously written, say in VB6?
I think as modules go they will be different. A module in a webapp has
VB Code:
Module Module1
...
...
End Module
This is really all I can think of.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|