PC Review


Reply
Thread Tools Rating: Thread Rating: 4 votes, 1.00 average.

How to call function from one aspx page from another

 
 
Jonathan
Guest
Posts: n/a
 
      5th Mar 2008
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.


 
Reply With Quote
 
 
 
 
Jialiang Ge [MSFT]
Guest
Posts: n/a
 
      5th Mar 2008
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 ((E-Mail Removed), 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.


 
Reply With Quote
 
Aidy
Guest
Posts: n/a
 
      5th Mar 2008
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)


"Jialiang Ge [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 ((E-Mail Removed), 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.
>
>
>



 
Reply With Quote
 
Jonathan
Guest
Posts: n/a
 
      5th Mar 2008
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






"Jialiang Ge [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 ((E-Mail Removed), 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.
>
>



 
Reply With Quote
 
Larry Bud
Guest
Posts: n/a
 
      5th Mar 2008
On Mar 5, 2:12*pm, "Jonathan" <n...@none.com> wrote:
> 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.
 
Reply With Quote
 
Jialiang Ge [MSFT]
Guest
Posts: n/a
 
      6th Mar 2008
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 ((E-Mail Removed), 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.

 
Reply With Quote
 
Jonathan
Guest
Posts: n/a
 
      6th Mar 2008
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?


"Jialiang Ge [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 ((E-Mail Removed), 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.
>



 
Reply With Quote
 
Jialiang Ge [MSFT]
Guest
Posts: n/a
 
      7th Mar 2008
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 ((E-Mail Removed), 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 Removed).

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

 
Reply With Quote
 
Jialiang Ge [MSFT]
Guest
Posts: n/a
 
      11th Mar 2008
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 ((E-Mail Removed), 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 Removed).

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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call a javascript when i call an aspx page with a form html not running on server Fabio Mastria Microsoft ASP .NET 4 28th Jan 2008 09:05 AM
Syntax for call from aspx page to .cs file then to different aspx page MadHatter51 Microsoft ASP .NET 1 17th May 2006 11:43 AM
Help: Call an ASPX page from a main ASPX page Progman Microsoft ASP .NET 2 13th Feb 2006 01:39 AM
Call function in codebehind from jscript in aspx page moondaddy Microsoft ASP .NET 2 27th Feb 2004 05:35 PM
how to call a function in another aspx page? Matthew Louden Microsoft ASP .NET 2 20th Nov 2003 08:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:02 PM.