473,695 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('O nUnload', '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 4051
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('O nUnload', '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.__EVENTTA RGET.value = 'OnUnload';
form1.__EVENTAR GUMENT.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.__EVENTTA RGET.value = 'OnUnload';
form1.__EVENTAR GUMENT.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******** *************@m 73g2000cwd.goog legroups.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('O nUnload', '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
2493
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 code: Sub Change(ByVal x, ByRef y) x = x+1 y = y+1 End Sub
1
2872
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 http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html#tag_02_04_03 The reason is, that if a signal is caught while your program is in the malloc routine, and the signal handler calls malloc or free again, then the heap will be corrupted, probably...
9
1839
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 state field in the collection, and every time something is inserted or deleted from the collection, I will just change the guid. Enumerator will just have to compare the guid received in the begging to the current one. If they are different, the...
3
5629
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 don’t have source safe on my home pc. Every time I open project at home it gives me missing source safe file error. This is really annoying. How can I fix this? Thanks
10
2798
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 of form2, the redirect will no longer work. I could write Response.Redirect(GetType(form2).Name + ".aspx")
7
1480
by: howa | last post by:
e.g. #include<iostream> using namespace std; int main() { double *d = new double;
0
2465
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 StopReader() method that simply aborts the worker thread (is there a better way for the above situation?). The StopReader creates an ObjectDisposedException when calling t.Abort(). WHY? Public Sub StopReader()
2
4182
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 connected to a SQL mdf., on the form I have a regexDataGridView for the table regex for navigation and viewing purpose only
0
8585
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9129
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9004
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2285
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.