How to call function from one aspx page from another

J

Jonathan

ASP VB.Net

How do I allow a function e.g. bolLoggedIn (the code of which resides in
startpage.aspx) to be accessed from other aspx pages so that I don't need to
duplicate the code in all pages that use bolLoggedIn?

TIA

P.S.

I haven't ever used a code behind page so to date am not really sure about
them. I have just embedded the VB.net code in the aspx pages. I only have
FrontPage so am not sure I can actually do VB.Net code-behind pages.
 
J

Jialiang Ge [MSFT]

Hello Jonathan,

We can put the code into a class, then call the code from code-behind of
the two pages.
Here is an example:

Suppose a function Add is needed in multiple pages' logic:
Function Add(byval a as integer, byval b as integer) as integer
Return a + b
End function

We can add a new class in the ASP.NET project by right clicking the
project, choose Add -> Class. Type the class name (e.g MyMath), and click
on OK. Visual studio will generate a MyMath.vb file in the App_code folder.
Then we put the Add code into the class.

If the code behind of both PageA.aspx and PageB.aspx need to call the
function, we can do it in this way:
Dim myMathObj as new MyMath
Dim result as integer = myMathObj.Add(1, 2)

If you have any other concerns or need anything else, please feel free to
let me know.

Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Aidy

Further to the above look into shared functions, esp if you don't need any
state stored between calls;

Shared Function Add(byval a as integer, byval b as integer) as integer
Return a + b
End function

Instead of;

Dim myMathObj as new MyMath
Dim result as integer = myMathObj.Add(1, 2)

you can use

Dim result as integer = MyMath.Add(1,2)
 
J

Jonathan

I don't have Visual Studio -- I am just coding in FrontPage directly.

In your scenario, what would be the text content of MyMath.vb?

I am assuming that:

Dim myMathObj as new MyMath

would know to look in a file called MyMath.vb?

Also if I have mypage.aspx, what is the statement within the <% %> to call
a function from mypage.vb page?

If I was to write a .vb page in Notepad, what is the text head in there
needed before I start writing:

MyFunction()


End Function

TIA
 
L

Larry Bud

I don't have Visual Studio -- I am just coding in FrontPage directly.

In your scenario, what would be the text content of MyMath.vb?

I am assuming that:

Dim myMathObj as new MyMath

would know to look in a file called MyMath.vb?

Also if I have mypage.aspx, what is the statement within the <%   %> to call
a function from  mypage.vb page?

If I was to write a .vb page in Notepad, what is the text head in there
needed before I start writing:

MyFunction()

End Function

I think it's folly to try to write asp.net code in anything but visual
studio. The Intellisense alone makes it a necessity. Note that there
is a free developer edition that you can download.
 
J

Jialiang Ge [MSFT]

Hello Jonathan,

As Larry said, a better tool to write ASP.NET code is Visual Studio. The
latest free edition is Visual Studio 2008 Express
http://www.microsoft.com/express/
You can download the Visual Web Developer 2008 for ASP.NET projects.

As for Frontpage, Frontpage also support "classes". We can new a text file
in Frontpage, rename the file to "MyMath.vb", then copy & paste the code
into it:

Public Class MyMath
Shared Function Add(ByVal a As Integer, ByVal b As Integer) As Integer
Return a + b
End Function
End Class

Then use the class in the codebehind of our aspx pages.

Hope it helps.
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jonathan

Thanks all of you for the information.

Will VS2008 interact correctly with my FP2K version? I have quite a lot of
pages on that FP site now.

Will it work on Windows 2000?
 
J

Jialiang Ge [MSFT]

Hello Jonathan,

Yes. Visual Studio 2008 can import Frontpage site in this way:
1. open Visual Studio 2008
2. File -> Open ->Web Site
3. In the Open Web Site dialog, choose File System in the left panel,
select the root directory of the frontpage site in the file system view.
and click on Open.

Visual Studio 2008 will work on Windows 2000.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
J

Jialiang Ge [MSFT]

Hello Jonathan,

I am writing to check the status of the issue. Would you mind letting me
know the result of the suggestions? If you need further assistance, feel
free to let me know. I will be more than happy to be of assistance.

Have a great day!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top