473,800 Members | 2,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PostbackUrl property issues after preventing user from posting asp.net page

I'm using asp.net 2.0. I have a page that has a save button and a
cancel button along with a text field. All controls are asp.net
server controls. I have JavaScript that prompts the user if he has
maninpulated data in the text field and then tries to leave the page.
The purpose is to prevent the user from accidentally losing his
changes. This JavaScript code that accomplishes this is based upon
the code found at http://aspnet.4guysfromrolla.com/articles/101304-1.aspx.
Basically it makes use of the window.onbefore unload event to prevent
navigation from the current page.

The cancel button has the PostbackUrl property set. The reason for
this is to navigate to the page the user was at before the current
page thus cancelling the operation. I understand that there are other
ways of achieving the scenario I have described here (i.e. hyperlink,
postback with a server redirect, etc.). I'm trying to keep this
example simple. Also, the save button does not have the PostbackUrl
property set as it is intended to cause a postback to the same page
and process the data.

So, here is the problem scenario. If the user manipulate's the text
in the text field and clicks the cancel button, he receives a prompt
that allows him to stop the current operation and stay on the current
page. What is happening is once this occurs, every other input
control on the form now will post to the URL set on the cancel
button's PostbackUrl property. Say the user now clicks the Save
button, they will not post back to the same page, and thus save the
data, they will post to the page specified by the cancel button's
PostbackUrl property.

I believe this has something to do with the code executed by
WebForm_DoPostB ackWithOptions, but I am not sure. It seems as if the
form's target gets reset to the postback url, maybe by this code, and
then you're stuck. Any suggestions on why this is occurring and how
to prevent it would be much appreciated.

Thanks!

Apr 20 '07 #1
2 6336
you are correct, the target url is changed then form.submit() is called,
which triggers your unload event (which is actually trigged by the start
of the load of the postback).

in RegisterStartup Script, save the original target url, and restore in
your unload event if canceled.

theForm.origTar get = theForm.target;
-- bruce (sqlwork.com)

no******@excite .com wrote:
I'm using asp.net 2.0. I have a page that has a save button and a
cancel button along with a text field. All controls are asp.net
server controls. I have JavaScript that prompts the user if he has
maninpulated data in the text field and then tries to leave the page.
The purpose is to prevent the user from accidentally losing his
changes. This JavaScript code that accomplishes this is based upon
the code found at http://aspnet.4guysfromrolla.com/articles/101304-1.aspx.
Basically it makes use of the window.onbefore unload event to prevent
navigation from the current page.

The cancel button has the PostbackUrl property set. The reason for
this is to navigate to the page the user was at before the current
page thus cancelling the operation. I understand that there are other
ways of achieving the scenario I have described here (i.e. hyperlink,
postback with a server redirect, etc.). I'm trying to keep this
example simple. Also, the save button does not have the PostbackUrl
property set as it is intended to cause a postback to the same page
and process the data.

So, here is the problem scenario. If the user manipulate's the text
in the text field and clicks the cancel button, he receives a prompt
that allows him to stop the current operation and stay on the current
page. What is happening is once this occurs, every other input
control on the form now will post to the URL set on the cancel
button's PostbackUrl property. Say the user now clicks the Save
button, they will not post back to the same page, and thus save the
data, they will post to the page specified by the cancel button's
PostbackUrl property.

I believe this has something to do with the code executed by
WebForm_DoPostB ackWithOptions, but I am not sure. It seems as if the
form's target gets reset to the postback url, maybe by this code, and
then you're stuck. Any suggestions on why this is occurring and how
to prevent it would be much appreciated.

Thanks!
Apr 20 '07 #2
On Apr 20, 11:14 am, bruce barker <nos...@nospam. comwrote:
you are correct, the target url is changed then form.submit() is called,
which triggers your unload event (which is actually trigged by the start
of the load of the postback).

in RegisterStartup Script, save the original target url, and restore in
your unload event if canceled.

theForm.origTar get = theForm.target;

-- bruce (sqlwork.com)

noney...@excite .com wrote:
I'm using asp.net 2.0. I have a page that has a save button and a
cancel button along with a text field. All controls are asp.net
server controls. I have JavaScript that prompts the user if he has
maninpulated data in the text field and then tries to leave the page.
The purpose is to prevent the user from accidentally losing his
changes. This JavaScript code that accomplishes this is based upon
the code found athttp://aspnet.4guysfro mrolla.com/articles/101304-1.aspx.
Basically it makes use of the window.onbefore unload event to prevent
navigation from the current page.
The cancel button has the PostbackUrl property set. The reason for
this is to navigate to the page the user was at before the current
page thus cancelling the operation. I understand that there are other
ways of achieving the scenario I have described here (i.e. hyperlink,
postback with a server redirect, etc.). I'm trying to keep this
example simple. Also, the save button does not have the PostbackUrl
property set as it is intended to cause a postback to the same page
and process the data.
So, here is the problem scenario. If the user manipulate's the text
in the text field and clicks the cancel button, he receives a prompt
that allows him to stop the current operation and stay on the current
page. What is happening is once this occurs, every other input
control on the form now will post to the URL set on the cancel
button's PostbackUrl property. Say the user now clicks the Save
button, they will not post back to the same page, and thus save the
data, they will post to the page specified by the cancel button's
PostbackUrl property.
I believe this has something to do with the code executed by
WebForm_DoPostB ackWithOptions, but I am not sure. It seems as if the
form's target gets reset to the postback url, maybe by this code, and
then you're stuck. Any suggestions on why this is occurring and how
to prevent it would be much appreciated.
Thanks!- Hide quoted text -

- Show quoted text -
I was nervous about doing this type of "override" of asp.net's
generated code/js. But you were right and this seems to work as far
as I can tell. Thanks!

Apr 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4130
by: Aaron Queenan | last post by:
I have a form which performs some asynchronous code. I want to display a wait cursor when it starts, and hide the wait cursor when it has completed. This part works fairly well, using: this.TopLevelControl.Cursor = System.Windows.Forms.Cursors.WaitCursor; I also want to prevent user interaction with the controls on my form while the wait cursor is displayed, so that use events (except resize and cancel) are blocked. What is the...
3
1070
by: Karl Lang | last post by:
Hi, I'm trying to set a property of a user control that is part of another user control. So I have a control A which contains control B, and I'm trying to set a property in B from within the codebehind file for A. In control codebehind for A in page_load : Protected objButtons As ProductButtons objButtons = DirectCast(FindControl("ProductButtons1"), ProductButtons) objButtons.ProductID = 8
1
1645
by: chavdar | last post by:
I need to inherit web user control page, how can I do this? Thanks, Chavdar
2
1104
by: Jeff Robichaud | last post by:
Hi, It is said the ErrorPage property of System.Web.UI.Page defines the target page where the browser will be redirected when un unhandled exception occurs. Doesn't seem to work...well it works fine at the application level (using web.config) but I thought that we could do it at the page level too ?? Maybe I misunderstood something...
0
1420
by: conckrish | last post by:
Hi all, Can anyone tell me how to add Click event for dynamically created User control page ?? I have a user control page in datagrid cell. when i click this user control page it ll redirect to another page. plz tell me how to add click event ??? Thanx.
6
3209
by: conckrish | last post by:
Hi all Can anyone tell me how to add a click event for a user control page dynamically??? Thanx Krish.
5
7285
by: RedHair | last post by:
I have a ASP.NET 2.0 web page which inherits a customized base page class and have a master page, their relation is as below Customized base page class --> web page --> master page How to access the property and control of master page from the customized base page class? Btw, I can access the server control of master page from base page class via
6
1524
by: David Hearn | last post by:
I have a property in a user control that I am setting: Private strPageName as String Public Property PageName() as String Get Return strPageName End Get Set(byVal Value as String) strPageName = Value End Set
1
2921
by: dr | last post by:
how to scroll a webbrowser control down a page, e.g. the same as if a user hit page-down?
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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
10033
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
7576
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
6811
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
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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.