Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

How to call function from one aspx page from another

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonathan - 05 Mar 2008 03:48 GMT
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.
Jialiang Ge [MSFT] - 05 Mar 2008 07:10 GMT
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  (jialge@online.microsoft.com, 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.
Aidy - 05 Mar 2008 09:28 GMT
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)

> Hello Jonathan,
>
[quoted text clipped - 30 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Jonathan - 05 Mar 2008 19:12 GMT
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

> Hello Jonathan,
>
[quoted text clipped - 28 lines]
> =================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
Larry Bud - 05 Mar 2008 20:33 GMT
> I don't have Visual Studio -- I am just coding in FrontPage directly.
>
[quoted text clipped - 15 lines]
>
> 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.
Jialiang Ge [MSFT] - 06 Mar 2008 03:18 GMT
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  (jialge@online.microsoft.com, 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.
Jonathan - 06 Mar 2008 11:39 GMT
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?

> Hello Jonathan,
>
[quoted text clipped - 24 lines]
> =================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
Jialiang Ge [MSFT] - 07 Mar 2008 02:23 GMT
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  (jialge@online.microsoft.com, 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:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
Jialiang Ge [MSFT] - 11 Mar 2008 06:47 GMT
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  (jialge@online.microsoft.com, 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:
msdnmg@microsoft.com.

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.