473,654 Members | 3,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I prevent the user from exiting a page?

I would like to prevent a user from exiting a page by clicking on
links. the only way he should be able to exit is clicking on a 'save'
button or a 'cancel' button. I can see that javascript is the only
way to prevent him from closing his browser completely before doing a
'save', but I was wondering if asp.net had a way of preventing him
from leaving the page by clicking on links. The following code does
not work - in fact it gives an error when it is tried
(response.redir ect is the statement that fails). Is there any way to
accomplish what I'm trying to do?

Protected Sub Page_Unload(ByV al sender As Object, ByVal e As
System.EventArg s) Handles Me.Unload
If Not Session("ExitVi aButton") Then
Session("BadExi tOfDOEditPage") = True
Response.Redire ct("~/Pages/home.aspx?
Pageload=DailyO utreachFormEdit ")
End If
End Sub

-- Marv
Nov 14 '08 #1
3 4717
"WISEMANOFNARNI A" <CO*********@LY COS.COMwrote in message
news:5d******** *************** ***********@a26 g2000prf.google groups.com...
I would like to prevent a user from exiting a page by clicking on links
Not 100%. You can experiment with the client-side JavaScript events
window.onunload and window.onbefore unload events, but these are not
reliable:
http://www.google.co.uk/search?hl=en...reunload&meta=
The following code does not work
Protected Sub Page_Unload
It appears you're under the misapprehension that the Page_Unload method runs
when a user closes / leaves a page. The Page_Unload method (like all other
server-side events) runs on the server, not the client. The Page_Unload
method is the final server-side method which is called after the page has
been fully rendered, streamed to the client, and is ready to be discarded.
At this point, page properties such as Response and Request are unloaded and
any cleanup is performed.

http://www.google.co.uk/search?hl=en...ifecycle&meta=
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 14 '08 #2
I would say that you are going to have to manually disable all of the
links except the save or cancel buttons. There are a couple of ways
to do that...

1. Add css to not show anchor tags. This may cause UI issues.

a {
display:none;
}

2. If the links are linkbutton or hyperlink controls you can set the
enabled property to false.

3. If they are not server controls you can remove the href property
from the anchor tag manually.

<a>Disabled Link</a>
instead of
<a href="http://www.google.com" >Enabled Link</a>
Nov 15 '08 #3
the idea is to attach OnClick event listener to every link on the page.
The best way to do it is to use JQuery library or you can iterate through
all link yourself.
But here is how it's done with JQuery

$('a').click(fu nction(event){
event.preventDe fault();
});
The $('a') selects all links and .click method attaches to each link the
OnClick event that performs JavaScript function.
event.preventDe fault will prevent from clicking on a link to go through.
George.


"WISEMANOFNARNI A" <CO*********@LY COS.COMwrote in message
news:5d******** *************** ***********@a26 g2000prf.google groups.com...
>I would like to prevent a user from exiting a page by clicking on
links. the only way he should be able to exit is clicking on a 'save'
button or a 'cancel' button. I can see that javascript is the only
way to prevent him from closing his browser completely before doing a
'save', but I was wondering if asp.net had a way of preventing him
from leaving the page by clicking on links. The following code does
not work - in fact it gives an error when it is tried
(response.redir ect is the statement that fails). Is there any way to
accomplish what I'm trying to do?

Protected Sub Page_Unload(ByV al sender As Object, ByVal e As
System.EventArg s) Handles Me.Unload
If Not Session("ExitVi aButton") Then
Session("BadExi tOfDOEditPage") = True
Response.Redire ct("~/Pages/home.aspx?
Pageload=DailyO utreachFormEdit ")
End If
End Sub

-- Marv
Nov 16 '08 #4

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

Similar topics

9
2277
by: Daniel Walzenbach | last post by:
Hi I am faced with the following problem: I have a page (let’s call this page page1.aspx) containing some TextBoxes and a hyperlink which opens another page (let’s call this page page2.aspx) as a popup using either window.open or window.showModalDialog. Since I want to warn the users of my application when they try to close page1.aspx and have changed the values in the meantime I thought about using the “onbeforeunload” event of the...
1
2681
by: The Fox | last post by:
How to prevent user to add web reference to my web services? Can I add password to web services so that only the users who know the password can add a web reference? Thanks in advance.
1
5722
by: User | last post by:
Hi, Are there ways to let browser forget about the previous submitted form data? Or prevent user from pressing F5 to submit the same form again Or prevent user from presising back on the browser? Please advise.
4
1757
neo008
by: neo008 | last post by:
Hi All, Can I prevent user to press cross button? I want to disable all three buttons for minimize, maximize and close for parent as well as child window. Is it possible? I'm using VB6. Can somebody help in this.
4
6650
by: Luqman | last post by:
How can I Prevent user from accessing any page directly without Login ? User should not be able to by pass the Login screen by typing the Url of any page directly. I am using ASP.Net 2.0 with Visual Studio 2005. Best Regards, Luqman
4
18134
by: =?Utf-8?B?QXNhZg==?= | last post by:
Hi, How can I prevent from an ASP.NET page to resend all the data again when the user press the Refresh button or F5 on the browser? Thanks in advanced, Asaf
5
21017
by: alvintiow | last post by:
Hi, I intend to use barcode for input and prevent user to modify the barcode they scan, user are not allow to input the barcode number by keyboard. Please advise how to do this. Thanks.
0
1454
by: helveticus | last post by:
I have a master/details configuration that includes multiple user controls. The details page is configured to cache data via VaryByCustom. This works fine. One of the user controls contains an image button. With caching turned on, the control remains "lame" since the control is only dynamically generated during the first access. My understanding is that page caching directive causes all page user controls to be implicitly cached as...
0
1327
by: Appyks | last post by:
How Do I prevent User from Locking the System? Obviously I can set following Windows registry value But it doesn’t serve my propose "DisableLockWorkstation"=dword:00000001 I need something as the code follows in here using System;
0
985
by: Roger Davies | last post by:
I have a Userform in VBA 2007 Excel on which I have several textboxes and a listbox. I am able to initiate the drag and drop but cannot work out how to prevent user from dropping the data into the wrong textboxes. I have searched the net but cannot find the answer to what must be a common problem. Can anyone help? - Please!!
0
8816
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
8709
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
8596
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...
0
7309
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5627
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
4150
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
2719
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
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
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.