Page Load event is called....

Discussion in 'ASP .Net' started by MooreSmnith, Jul 7, 2004.

  1. MooreSmnith

    MooreSmnith Guest

    When I navigate to the next page using
    Response.Rediect("MyNextPage.aspx") current page Page_Load event is called.
    What I may wrongly understood is that post back will happen whenever there
    is any server side event happens, resulting in Page_load event. Page_Load is
    also happening when I navigate to the next page. That means Page_load will
    always happen when I navigate to the next page. Please correct me If I have
    totally misunderstood this concepts.
    Moore Smith
     
    MooreSmnith, Jul 7, 2004
    #1
    1. Advertising

  2. On Tue, 6 Jul 2004 16:55:06 -0700, MooreSmnith <>
    wrote:

    > When I navigate to the next page using
    > Response.Rediect("MyNextPage.aspx") current page Page_Load event is
    > called.
    > What I may wrongly understood is that post back will happen whenever
    > there
    > is any server side event happens, resulting in Page_load event.
    > Page_Load is
    > also happening when I navigate to the next page. That means Page_load
    > will
    > always happen when I navigate to the next page. Please correct me If I
    > have
    > totally misunderstood this concepts.
    > Moore Smith
    >
    >
    >
    >
    >


    I think what you're saying is correct (I may not understand your
    details). The Page_Load is called when the page is first loaded, or
    posted back to, etc. Think of it as a Page object receives a request.
    When a request comes in, it tries to find that page (via the URL) and
    creates an instance of that Page class. This is because the web is
    stateless, it has to recreate it each time (even tho .NET gives us a
    little magic for keeping 'state' in other ways).

    When you do a redirect, you are telling the browser in the current
    response that the page it should load is somewhere else (a different URL);
    the browser then makes a new (GET) request at this new URL, hence an
    instance of your second page is created and loaded....

    and the cycle goes on :)

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
     
    Craig Deelsnyder, Jul 7, 2004
    #2
    1. Advertising

  3. MooreSmnith

    EijiTek Guest

    Every ASP.NET page is an instance of a class and therefore each page has its
    own life cycle. Each page has a Page_Load event that is called as part of
    the life cycle of every page, not just on post back. If you want certain
    code to only run when a postback occurs you can test for it with
    Page.IsPostBack.

    Response.Redirect results in a response being sent to the client,
    instructing it (the client) to open a different page instead of the one
    originally requested. Server.Transfer on the other hand occurs on the
    server and skips the additional HTTP request but neither method will supress
    the call to the Page_Load event handler on the next page.

    "MooreSmnith" <> wrote in message
    news:...
    > When I navigate to the next page using
    > Response.Rediect("MyNextPage.aspx") current page Page_Load event is

    called.
    > What I may wrongly understood is that post back will happen whenever there
    > is any server side event happens, resulting in Page_load event. Page_Load

    is
    > also happening when I navigate to the next page. That means Page_load will
    > always happen when I navigate to the next page. Please correct me If I

    have
    > totally misunderstood this concepts.
    > Moore Smith
    >
    >
    >
    >
    >
     
    EijiTek, Jul 7, 2004
    #3
  4. MooreSmnith

    MooreSmnith Guest

    My question is when the response.Redirect is executed, page_load event of
    the page(Page 1) which has Response.Redirect and the Redirected(Page 2) page
    Page_load event is getting called. I am not understanding why the the
    Page_Load event of Page 1 is called. Calling Page 2 Page_Load evevnt is
    understandable.
    Thanks for your answers and helping me to understand this flow.
    Moore.


    "EijiTek" <> wrote in message
    news:...
    > Every ASP.NET page is an instance of a class and therefore each page has

    its
    > own life cycle. Each page has a Page_Load event that is called as part of
    > the life cycle of every page, not just on post back. If you want certain
    > code to only run when a postback occurs you can test for it with
    > Page.IsPostBack.
    >
    > Response.Redirect results in a response being sent to the client,
    > instructing it (the client) to open a different page instead of the one
    > originally requested. Server.Transfer on the other hand occurs on the
    > server and skips the additional HTTP request but neither method will

    supress
    > the call to the Page_Load event handler on the next page.
    >
    > "MooreSmnith" <> wrote in message
    > news:...
    > > When I navigate to the next page using
    > > Response.Rediect("MyNextPage.aspx") current page Page_Load event is

    > called.
    > > What I may wrongly understood is that post back will happen whenever

    there
    > > is any server side event happens, resulting in Page_load event.

    Page_Load
    > is
    > > also happening when I navigate to the next page. That means Page_load

    will
    > > always happen when I navigate to the next page. Please correct me If I

    > have
    > > totally misunderstood this concepts.
    > > Moore Smith
    > >
    > >
    > >
    > >
    > >

    >
    >
     
    MooreSmnith, Jul 7, 2004
    #4
  5. MooreSmnith

    EijiTek Guest

    As I mentioned, each page has a life cycle therefore, requesting a page
    starts the life cycle. In order to perform a redirect you have to be
    executing code from the first page.

    Where in Page1 are you making the call to Response.Redirect()?


    "MooreSmnith" <> wrote in message
    news:...
    > My question is when the response.Redirect is executed, page_load event of
    > the page(Page 1) which has Response.Redirect and the Redirected(Page 2)

    page
    > Page_load event is getting called. I am not understanding why the the
    > Page_Load event of Page 1 is called. Calling Page 2 Page_Load evevnt is
    > understandable.
    > Thanks for your answers and helping me to understand this flow.
    > Moore.
    >
    >
    > "EijiTek" <> wrote in message
    > news:...
    > > Every ASP.NET page is an instance of a class and therefore each page has

    > its
    > > own life cycle. Each page has a Page_Load event that is called as part

    of
    > > the life cycle of every page, not just on post back. If you want

    certain
    > > code to only run when a postback occurs you can test for it with
    > > Page.IsPostBack.
    > >
    > > Response.Redirect results in a response being sent to the client,
    > > instructing it (the client) to open a different page instead of the one
    > > originally requested. Server.Transfer on the other hand occurs on the
    > > server and skips the additional HTTP request but neither method will

    > supress
    > > the call to the Page_Load event handler on the next page.
    > >
    > > "MooreSmnith" <> wrote in message
    > > news:...
    > > > When I navigate to the next page using
    > > > Response.Rediect("MyNextPage.aspx") current page Page_Load event is

    > > called.
    > > > What I may wrongly understood is that post back will happen whenever

    > there
    > > > is any server side event happens, resulting in Page_load event.

    > Page_Load
    > > is
    > > > also happening when I navigate to the next page. That means Page_load

    > will
    > > > always happen when I navigate to the next page. Please correct me If I

    > > have
    > > > totally misunderstood this concepts.
    > > > Moore Smith
    > > >
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    EijiTek, Jul 7, 2004
    #5
  6. MooreSmnith

    MooreSmnith Guest

    Yes,
    I am making Response.Redirect from page 1.
    Thanks for your response. To conclude, to redirect to different page it has
    to postback itself.
    Moore


    "EijiTek" <> wrote in message
    news:p...
    > As I mentioned, each page has a life cycle therefore, requesting a page
    > starts the life cycle. In order to perform a redirect you have to be
    > executing code from the first page.
    >
    > Where in Page1 are you making the call to Response.Redirect()?
    >
    >
    > "MooreSmnith" <> wrote in message
    > news:...
    > > My question is when the response.Redirect is executed, page_load event

    of
    > > the page(Page 1) which has Response.Redirect and the Redirected(Page 2)

    > page
    > > Page_load event is getting called. I am not understanding why the the
    > > Page_Load event of Page 1 is called. Calling Page 2 Page_Load evevnt is
    > > understandable.
    > > Thanks for your answers and helping me to understand this flow.
    > > Moore.
    > >
    > >
    > > "EijiTek" <> wrote in message
    > > news:...
    > > > Every ASP.NET page is an instance of a class and therefore each page

    has
    > > its
    > > > own life cycle. Each page has a Page_Load event that is called as

    part
    > of
    > > > the life cycle of every page, not just on post back. If you want

    > certain
    > > > code to only run when a postback occurs you can test for it with
    > > > Page.IsPostBack.
    > > >
    > > > Response.Redirect results in a response being sent to the client,
    > > > instructing it (the client) to open a different page instead of the

    one
    > > > originally requested. Server.Transfer on the other hand occurs on the
    > > > server and skips the additional HTTP request but neither method will

    > > supress
    > > > the call to the Page_Load event handler on the next page.
    > > >
    > > > "MooreSmnith" <> wrote in message
    > > > news:...
    > > > > When I navigate to the next page using
    > > > > Response.Rediect("MyNextPage.aspx") current page Page_Load event is
    > > > called.
    > > > > What I may wrongly understood is that post back will happen whenever

    > > there
    > > > > is any server side event happens, resulting in Page_load event.

    > > Page_Load
    > > > is
    > > > > also happening when I navigate to the next page. That means

    Page_load
    > > will
    > > > > always happen when I navigate to the next page. Please correct me If

    I
    > > > have
    > > > > totally misunderstood this concepts.
    > > > > Moore Smith
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    MooreSmnith, Jul 7, 2004
    #6
  7. MooreSmnith

    EijiTek Guest

    A redirect is not a postback nor does it require a postback to function. A
    postback only occurs when you submit the webform such as with a button press
    or other server side event triggered by a client side action. Within the
    life cycle of a page certain events are called by the ASP.NET runtime such
    as OnInit(), OnLoad(), and OnPreRender() regardless of whether a postback
    has occured or not.

    As I mentioned in my previous post, you can check Page.IsPostBack to
    determine if a postback occured if you have code that you only want to run
    when a postback occurs. Performing a postback is not necessary to call
    Response.Redirect or Server.Transfer though it it more common for the
    redirection to occur after a postback.

    Here's an example (not the greatest but it works) Say you have a production
    system and you're replacing one page with another but you don't want to
    update all of the links right now because there are too many to find them
    all or multiple systems that you don't have control over reference the page.
    You could add a call to Response.Redirect() to perform the redirection to
    the replacement page as soon as the page is requested or you could place a
    note on the page telling people that the page has been replaced by another
    page and you provide a Button (call it RedirectButton) control that, when
    clicked, will call RedirectButton_OnClick() which in turn calls
    Response.Redirect(). In either scenario, you'll be requesting Page1 which
    will redirect to Page2 which means that a new instance of Page1 will be
    created, the code for the page will execute, then when redirected, a new
    instance of Page2 will be created and its code will be executed. One
    mechanism requires a postback while the other doesn't. Whether the page
    needs to perform a postback is determined by the needs of your application.

    "MooreSmnith" <> wrote in message
    news:...
    > Yes,
    > I am making Response.Redirect from page 1.
    > Thanks for your response. To conclude, to redirect to different page it

    has
    > to postback itself.
    > Moore
    >
    >
    > "EijiTek" <> wrote in message
    > news:p...
    > > As I mentioned, each page has a life cycle therefore, requesting a page
    > > starts the life cycle. In order to perform a redirect you have to be
    > > executing code from the first page.
    > >
    > > Where in Page1 are you making the call to Response.Redirect()?
    > >
    > >
    > > "MooreSmnith" <> wrote in message
    > > news:...
    > > > My question is when the response.Redirect is executed, page_load event

    > of
    > > > the page(Page 1) which has Response.Redirect and the Redirected(Page

    2)
    > > page
    > > > Page_load event is getting called. I am not understanding why the the
    > > > Page_Load event of Page 1 is called. Calling Page 2 Page_Load evevnt

    is
    > > > understandable.
    > > > Thanks for your answers and helping me to understand this flow.
    > > > Moore.
    > > >
    > > >
    > > > "EijiTek" <> wrote in message
    > > > news:...
    > > > > Every ASP.NET page is an instance of a class and therefore each page

    > has
    > > > its
    > > > > own life cycle. Each page has a Page_Load event that is called as

    > part
    > > of
    > > > > the life cycle of every page, not just on post back. If you want

    > > certain
    > > > > code to only run when a postback occurs you can test for it with
    > > > > Page.IsPostBack.
    > > > >
    > > > > Response.Redirect results in a response being sent to the client,
    > > > > instructing it (the client) to open a different page instead of the

    > one
    > > > > originally requested. Server.Transfer on the other hand occurs on

    the
    > > > > server and skips the additional HTTP request but neither method will
    > > > supress
    > > > > the call to the Page_Load event handler on the next page.
    > > > >
    > > > > "MooreSmnith" <> wrote in message
    > > > > news:...
    > > > > > When I navigate to the next page using
    > > > > > Response.Rediect("MyNextPage.aspx") current page Page_Load event

    is
    > > > > called.
    > > > > > What I may wrongly understood is that post back will happen

    whenever
    > > > there
    > > > > > is any server side event happens, resulting in Page_load event.
    > > > Page_Load
    > > > > is
    > > > > > also happening when I navigate to the next page. That means

    > Page_load
    > > > will
    > > > > > always happen when I navigate to the next page. Please correct me

    If
    > I
    > > > > have
    > > > > > totally misunderstood this concepts.
    > > > > > Moore Smith
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    EijiTek, Jul 7, 2004
    #7
    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. Samy
    Replies:
    2
    Views:
    1,359
  2. GauravGupta
    Replies:
    4
    Views:
    2,109
    Shilpa1234
    Jan 19, 2012
  3. S_K
    Replies:
    6
    Views:
    1,188
    Robert Dunlop
    Nov 8, 2007
  4. Matcon
    Replies:
    3
    Views:
    21,588
    Matcon
    May 28, 2008
  5. sysdesigner

    Datagrid events only fire if Databind is called in Page Load event

    sysdesigner, Jun 28, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    157
    Teemu Keiski
    Jul 2, 2005
Loading...

Share This Page