Call a function from another page

Discussion in 'ASP .Net' started by Carlos A., Sep 3, 2006.

  1. Carlos A.

    Carlos A. Guest

    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.
    Carlos A., Sep 3, 2006
    #1
    1. Advertising

  2. Carlos A.

    Tim_Mac Guest

    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
    Tim_Mac, Sep 3, 2006
    #2
    1. Advertising

  3. Carlos A.

    Mark Rae Guest

    "Carlos A." <> wrote in message
    news:...

    > 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...
    Mark Rae, Sep 3, 2006
    #3
  4. Carlos A.

    Carlos A. Guest

    Thanks a lot.

    "Tim_Mac" <> wrote in message
    news:%23jKyd%...
    > 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
    >
    Carlos A., Sep 4, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sandeep Chikkerur
    Replies:
    1
    Views:
    725
    Jack Klein
    Nov 18, 2003
  2. grbgooglefan
    Replies:
    2
    Views:
    423
    Pascal Bourguignon
    Jan 30, 2008
  3. grbgooglefan
    Replies:
    4
    Views:
    442
    Kenny McCormack
    Jan 30, 2008
  4. grbgooglefan
    Replies:
    0
    Views:
    392
    grbgooglefan
    Jan 30, 2008
  5. Randell D.
    Replies:
    38
    Views:
    292
    askMe
    Jul 19, 2005
Loading...

Share This Page