Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > .NET Framework 1.x
|
.NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2006, 10:47 AM
Registered User
 
Join Date: Sep 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Detecting PostBack event in Page_Unload

Hi

I have a form which will update a database row. The app is multi-user app.

Unfortunately, the database HAS to use pessimistic application locking, which means that when an existing row is read into the form for editing, a bit/tinyint is flipped to lock the record from other users.

This is all OK - when the user has finished updating or clicks 'cancel' the row is unlocked again.

However - if a user starts to edit and cancels by clicking the back button or navigates away, this leaves the row locked.

My solution was to unlock the record in Page_Unload as this will fire if the backbutton is clicked, but doing this will also unlock the record for a postback (not good if the user is updating).

My question is - how can I detect whether a postback has been raised in the Page_Unload sub/event? I'm assuming the Page.IsPostBack test won't work as this will just determine whether the current page being viewed is a post back.

In pseudo code, I would lie to do something like:

Code:
Sub Page_Unload

    If "PostBackEventHasBeenRaised" Then
         'Do postback as normal
    Else
        'Unlock the current record being edited
    End If


End Sub
I'm hoping there is a simple answer (e.g. an equivalent of Page.IsPostBack but for the post back event)!

Cheers

Graham.

 
Old May 23rd, 2006, 05:06 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubhav.kumar
Default

hi,

i can tell you a way but you have ride on it till end to get it working. Its a hint.

On the page unload event in ASPX page use javascript to manually postback your page before a new page is loaded. This way if user used back button or else, you page will always get posted and you can handle the things in code behind then

For this run your project for any page which gets posted back. View the html source generated. You will get a javascript methoid there name _doPostBack or similar.

Just hang around the code to see how your other controls are getting posted back. Then use the same functionality on page unload event for <body> tag

Pls note that you have synchronize the normal post back [button click or anything else] with this manual post back

A little tricky, unfortunately i can't provide code due to my limitations. But i know you can do it

Anubhav Kumar





Similar Threads
Thread Thread Starter Forum Replies Last Post
grid view row editing event fired after postback sasidhar79 ASP.NET 2.0 Professional 0 January 30th, 2007 08:17 PM
Detecting a Yahoo Toolbar MosheGolden Classic ASP Professional 0 November 23rd, 2006 02:32 AM
detecting SQL server down geogomez SQL Server 2000 3 August 1st, 2006 08:04 AM
detecting a form nfontaine Javascript How-To 2 April 20th, 2004 06:53 AM
Detecting Read-Only rgerald Access VBA 6 October 30th, 2003 04:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.