473,409 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Safe detect url change

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
4 4005
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Paul Paterson | last post by:
I am trying to find a way to mimic by-reference argument passing for immutables in Python. I need to do this because I am writing an automated VB to Python converter. Here's an example of the VB...
1
by: Michael Pronath | last post by:
Hi, can I make sure that Python uses only async-signal safe glibc functions in signal handlers? For example, you must not call malloc or free in signal handlers, see...
9
by: Sasha | last post by:
Hi, I am extending standard IEnumerator, and I was just wondering what is the best way to make enumarator safe? What do I mean by safe? Detect deletes and all... My idea is to have private Guid...
3
by: Job Lot | last post by:
I am having loads of problem using vb.net project under visual source safe. I’ll start with How can I exclude source safe information from the project when I take a copy of project home? I...
10
by: Urs Eichmann | last post by:
If I have two webforms, form1.aspx and form2.aspx, and I want to do a Response.Redirect from form1 to form2, I can write Response.Redirect("form2.aspx") However, if somebody changes the name...
7
by: howa | last post by:
e.g. #include<iostream> using namespace std; int main() { double *d = new double;
0
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I read from a serialport using a worker thread. Because the worker thread t does not loop often, I cannot wait to terminate the worker thread using a boolean in the While condition. So I have a...
2
by: GS | last post by:
How do I properly detect row change before allowing moving to next row? I tried using RowLeave . here is brief descript of the form setup. I have ieStringTmpDataSetwith regex table...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.