Call a function from another page

C

Carlos A.

Hello all
VB Code.
I have a Page1.aspx that opens a Page2.aspx, this page has a button_ok
How can I call a Function (in Page1) when I press the button_ok (in Page2) ?

Thanks a lot.
 
T

Tim_Mac

hi Carlos
every page in asp.net is a class. so from Page 2, you can use the following
code:

dim myPage1 as new Page1()
myPage1.FunctionWhatever()

you must understand though that you would just be creating a page object
with a scope/lifetime limited to the current block of code you are in (e.g.
Page2.button_ok_click).

what you should really do in your situation is organise your code better.
if you have shared code that is needed by Page1 and Page2 then it should be
in a class of its own. if you're using .Net2, just put a new class file
into App_Code which is the shared code folder. otherwise just insert a new
class anywhere in the application, then it can be used by any page in your
site, without having to go creating Page objects just to use the code
contained in them. the code i've written above is a really poor way of
sharing code between pages, unless it is absolutely necessary, and even then
i can't think of a good reason why you would want to do this. just suppose
that later on in the development of your site, you decide to delete Page1,
but ooops you forgot you had code in there that Page2 is dependent on, so
you break the site and have to pull out the code.

a page should be encapsulated, without having dependencies on other pages.
otherwise you will end up with a monster of a web site with so many
inter-dependencies between pages that it will be very difficult to maintain.

tim
 
M

Mark Rae

How can I call a Function (in Page1) when I press the button_ok (in Page2)
?

I suggest you follow Tim_Mac's advice - I can't really add anything to it...
 

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

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top