Page uload occurs two times when redirecting

Discussion in 'ASP .Net' started by mortb, Apr 8, 2005.

  1. mortb

    mortb Guest

    Hi,

    I'm overriding OnUload in my pages. I've put the Connection.Close in the
    method.
    But I have noticed that the method is run twice if I do a Response.Redirect
    in the page.
    Do some one know why?

    cheers,
    mortb
     
    mortb, Apr 8, 2005
    #1
    1. Advertising

  2. mortb

    Brock Allen Guest

    I'm not sure what your problem is; But I'd like to comment on your approach
    to database connection management. I'd suggest not opening a connection early
    and closing it late as it seems you're doing in the page. I'd suggest instead
    opening it late and closing it early. IOW, open the connection right when
    you need it, use it (get your data, update, whatever), then close it right
    there and then (in your Page_Load or Button_Click or whereever). Connections
    are pooled so in a miltiuser environment like ASP.NET you'll have good chances
    of reusing open connections that have been put back into the pool.

    Also, it helps to make sure that you never have any idle connections. If
    you open the connection in Page_Load, say, and close it in Unload... well,
    there are cycles where the connection is doing nothing, but it's allocated
    and owned by your page an unusable to anyone else. So putting it back in
    the pool ASAP let others use it and you end up using fewer connections at
    the same time.

    Lastly, opening late and closing early makes for less buggy code and less
    chances for a leak of the connection.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi,
    >
    > I'm overriding OnUload in my pages. I've put the Connection.Close in
    > the
    > method.
    > But I have noticed that the method is run twice if I do a
    > Response.Redirect
    > in the page.
    > Do some one know why?
    > cheers,
    > mortb
     
    Brock Allen, Apr 8, 2005
    #2
    1. Advertising

  3. mortb

    Josh Guest

    Good Advice! I wonder if Mortb is an ex Windows Developer, they seem to
    think like that?
     
    Josh, Apr 8, 2005
    #3
  4. mortb

    MattC Guest

    Or better still implement your connection management in a seperate layer
    that closes the connection after the command is executed and have nodb
    management code in your Page_Load or Button_Click events :)

    MattC

    "Brock Allen" <> wrote in message
    news:...
    > I'm not sure what your problem is; But I'd like to comment on your
    > approach to database connection management. I'd suggest not opening a
    > connection early and closing it late as it seems you're doing in the page.
    > I'd suggest instead opening it late and closing it early. IOW, open the
    > connection right when you need it, use it (get your data, update,
    > whatever), then close it right there and then (in your Page_Load or
    > Button_Click or whereever). Connections are pooled so in a miltiuser
    > environment like ASP.NET you'll have good chances of reusing open
    > connections that have been put back into the pool.
    > Also, it helps to make sure that you never have any idle connections. If
    > you open the connection in Page_Load, say, and close it in Unload... well,
    > there are cycles where the connection is doing nothing, but it's allocated
    > and owned by your page an unusable to anyone else. So putting it back in
    > the pool ASAP let others use it and you end up using fewer connections at
    > the same time.
    >
    > Lastly, opening late and closing early makes for less buggy code and less
    > chances for a leak of the connection.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    >> Hi,
    >>
    >> I'm overriding OnUload in my pages. I've put the Connection.Close in
    >> the
    >> method.
    >> But I have noticed that the method is run twice if I do a
    >> Response.Redirect
    >> in the page.
    >> Do some one know why?
    >> cheers,
    >> mortb

    >
    >
    >
     
    MattC, Apr 8, 2005
    #4
  5. mortb

    Josh Guest

    > Or better still implement your connection management in a seperate layer
    > that closes the connection after the command is executed and have nodb
    > management code in your Page_Load or Button_Click events :)


    I think OO is dead. The new thing is code in the UI!
     
    Josh, Apr 8, 2005
    #5
  6. mortb

    Brock Allen Guest

    Brock Allen, Apr 8, 2005
    #6
    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. =?Utf-8?B?bWF2cmlja18xMDE=?=

    SetAuthCookie works some times and fails some times?

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    567
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 23, 2006
  2. laredotornado
    Replies:
    6
    Views:
    535
    Teraposa Lunodas
    Nov 24, 2009
  3. Jim Burgess
    Replies:
    11
    Views:
    399
    Jim Burgess
    Oct 9, 2009
  4. Thomas Greenwood
    Replies:
    7
    Views:
    181
    David Jacobs
    May 15, 2011
  5. libsfan01
    Replies:
    7
    Views:
    129
    Dr John Stockton
    Aug 13, 2006
Loading...

Share This Page