Sunday, April 3, 2011

Asp.Net de bir Page_UnLoad Eventi

 
Bugün asp.net çalışırken kafamıza takılan bir sorun vardı.Page _Unload eventinin
gerçekleştirdiği ana görev ve arkaplanda dönen entrikaların neler olduğu !
Biraz gezindikten sonra blogların  birinde aşağıdaki diyalog a rastladım .
Merak edenlere yardımcı olabilir .

Larry morris web forma link butonu ile yapıştırdığı kodun Page Unload eventini
2 kez  çalıştırdığından ve Responce.redirect i kaldırdığında  problemin
çözüldüğünden bahsetmiş .Web Sayfaları ile Page _Unload eventi arasındaki
bağlantıyı merak ettiğini söylemiş .

Larry Morris


The following code, pasted into a web form with a link button on it, will
cause the page_unload event to fire twice. If I remove the
response.redirect, the problem goes away :). I've got a work around, but I'm
curious how one is supposed to programmatically navigate between web pages
without the page_unload event firing twice.

Thanks,

Larry Morris



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load


'Put user code to initialize the page here


Stop


End Sub


Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Unload


Stop


End Sub


Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles LinkButton1.Click


Response.Redirect("http://www.microsoft.com")


End Sub


End Class
--------------------------------------------------------
Sayfa ilk kez yüklendiğinde ,en son yapılacak olan HTML kodunun browser a  dönüşümünden hemen önce Page_Unload ilk kez çağırılır.
Daha sonra link button Page_Unload u  tekrar çağıracak olan ,Page Postback i çağırır.Eğer  Page_Unload ı bir kez çağırmak isterseniz Is post back i filtreleyecek olan Try Catch Blogunuz kullanın"   demiş HTH 

As the page is loaded the first time, it will invoke Page_Unload the
first time finally but just before rendering the HTML content to the
browser,


Then the link button will invoke page postback, in which the
page_unload will be invoked again.

If just want to invoke once, try to use if(IsPostBack) to filter it.
HTH.
"Bu durumda neler olacağını biliyorum ",diyerek durumları sıralamış ve Page_Unload event inin Response.redirect ile ilgisini açıklamaya başlamış.

T.Z
I know that; What happens in this case is:

Page_Load,
Page_Unload,

Page_Load,
LinkButton1_Click,
Page_Unload,
Page_Unload.

Notice the Page_Unload event fired twice. What is it about the
Response.Redirect causes two page_unload events?
every page request has a load and unload. a redirect in the response tells
the browser to request a new page. page unload has nothing to do with the
browser, its just the last step in the creating the html for the page, it
used to release objects you created during building the page.

Her sayfa isteği load ve unload edilir.Cevaptaki(response) yönlendirme ,browser a yeni bir sayfa isteğinin olduğunu iletir.Page_Unload ın browser ile ilgisi yoktur ,Bu sayfa için HTML oluşturmanın son adımıdır ve server da sayfanın inşası sırasında oluşturulmuş nesneleri serbest bırakmak için kullanılır "  diyerek konuya noktayı koymuş .Bence açıklayıcıydı umarım sizin için de öyledir ve faydalı olmuştur.

-- bruce (sqlwork.com)

No comments:

Kendi Çalışmalarım

Kendi Çalışmalarım
2015

Kendi Çalışmalarım

Kendi Çalışmalarım
2015

Kendi Çalışmalarım

Kendi Çalışmalarım
2015

Kendi Çalışmalarım

Kendi Çalışmalarım
2011

Kendi Çalışmalarım

Kendi Çalışmalarım
2009

Kendi Çalışmalarım

Kendi Çalışmalarım
2007

Kendi Çalışmalarım

Kendi Çalışmalarım
2008

Kendi Çalışmalarım

Kendi Çalışmalarım
2015

Kendi Çalışmalarım

Kendi Çalışmalarım
2009