By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,569 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,569 IT Pros & Developers. It's quick & easy.

Safe detect url change

P: n/a
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 ?

Aug 8 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

"Dst" wrote:
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 ?

Aug 8 '06 #2

P: n/a
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

clickon wrote:
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.
Aug 8 '06 #3

P: n/a
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


"Dst" wrote:
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

clickon wrote:
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.

Aug 8 '06 #4

P: n/a
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.
--
Regards

John Timney (MVP)
"Dst" <ds******@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
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 ?

Aug 8 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.