Safe detect url change

D

Dst

This is what i'm trying to do:
I'm porting a windows app to a web app.
I have a webform which will edit some data stored in a database.
The data needs to be locked in the database, while editing.

On first page load:
Create a custom rowlock object and store it in viewstate.

When user clicks on edit, retrieve the viewstate object and lock
the row in the database.

If the user clicks cancel: restore, retrieve the viewstate object and
unlock the row.
If the user clicks save: save, retrieve the viewstate object and unlock
the row.

Now this works if the user always clicks cancel/save after a edit.

Problem is, if the user clicks back in the browser or goes to another
url,
while editing i dont get any postbacks.

I found this to force a postback on unload:

<script for="window" event="onunload">
__doPostBack('OnUnload', 'Unloading');
</script>

Now i get a postback if the user tryes to navigate to another url, but
the unload event is fired on every postback messing up the viewstate
of all my controls for some reason..

Then i found this:
<script for="window" event="onunload">
form1.target = 'OnUnload';
form1.submit();
</script>
Now this also fires a postback when navigating to another url, and
doesn't seem to mess up the viewstate of the form.
But i dont understand of i can detect this postback event in the
codebehind.
__EventTarget is empty on postback. Everything is empty..

If i can safely detect this postback, then i can unlock the db object
and redirect to the original request/new url issued by the user.
But how can i retrieve the requested url ?

I will only be using IE browsers in this app, if that helps.

Anyone ?
 
G

Guest

Can you not take a different aproach. When working with data connected web
apps you have to always bear in mind that the web is stateless and you are
essentially working with a disconnected data set when editing data. Rather
than trying to fruitlessly emulate the statefull behaviour of a windows forms
app where you can remain connected to the data source whilst the editing
takes place, why don't you leave the table/record unlocked and then try to
catch an exception if the underlying record has changed during editing.
 
D

Dst

That would require too much work. And adding a lastupdated timestamp to
the
db is not possible for now.

Anyway, found a way to send and detect the proper unload postback
event.

<script for="window" event="onunload">
form1.__EVENTTARGET.value = 'OnUnload';
form1.__EVENTARGUMENT.value = 'Unloading';
form1.submit();
</script>

But this doesnt help much i'm afraid since the unload event
is fired for every postback, and i cant seem to detect if the url is
changing in the javascript or in the code behind...
It would have worked perfectly if i could detect a url change...

Dst
 
G

Guest

Dst,
You should really consider adding a rowversion (timestamp) column to the
Database table and include this along with the primary key in your update
code. Normally if this is added as the last column in a table it will not
upset other code.
The arrangement you have come up with is likely to cause you considerable
problems. Just my 2 cents!
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 
J

John Timney \(MVP\)

As you have found, viewstate is dependent on the client actually being there
and interacting with your server where the session object is dependent on
the client having an active session. If you store the object in session, or
an indicator that you have a lock active in viewstate then a session timeout
triggering session on_end could see it removed if the user closed their
browser or navigated away.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top