473,408 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Call a function from another page

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.
Sep 3 '06 #1
3 1893
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
Sep 3 '06 #2
"Carlos A." <ca*******@gmail.comwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
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...
Sep 3 '06 #3
Thanks a lot.

"Tim_Mac" <ti********@community.nospamwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
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

Sep 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Michael | last post by:
Hello everybody, Newbie here. I've been working on this for the last two days and I can't figure out where this problem is. I think it's something so obvious, but I can't see it! OK, firstly...
3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
4
by: dale zhang | last post by:
Hi, I have the following private function in one page: private string Connect() { string sConnect; // this value could go directly in the Global.asax.vb declarations switch...
3
by: KaNos | last post by:
Hi, "robot script pages" are html+javascript pages, can be played in aspx player. So in this tech, robot call aspx player's function (an interface is sheared) and wait a result synchronously with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.