Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2007, 04:36 PM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can't stop programatically an asp.net 2, app

All:

It's frequently the simplest things that 'get' me.

I've got a multipage asp.net 2 app website with many pages. I want to put a button on each and every page that when the user clicks, the app ends and their computer returns to where ever it was before they started the app.

Darned if I can find a way to do this. In Asp.net 1.1 one could code: Application.Exit(). But, there is no Exit method in the Application object in asp.net 2.
Help, anyone?

VictorVictor

 
Old January 31st, 2007, 04:52 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

What is it that you expect to happen???

"Application" runs on the server, so what do you want it do do there? I don't think you want to shut down the server, do you?

I think what you're looking for is the JavaScript Close method that closes the browser running on the *client*. Since each request to the server is stateless, and the server generally doesn't know much about you after each request, closing down the browser is usually enough.

See here for more info about the Close method:

http://www.javascript-coder.com/wind...ow-close.phtml


Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old January 31st, 2007, 05:07 PM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Imar:

Thanks for the reply.

Yes, exactly, I want the user's browser to return to the state it was in just before the user clicked on the link to begin a session at my webiste, and the server to stop running the code for the application.

I want this to happen without the user having to use his/her mouse to click on the big X button in the IE6/IE7 upper right corner. One click on my app's button should emulate the functionality of the window's X button and be done with it -- no more user clicks should be needed to exit.

I'll check out the javascript function you referenced and see if that will give me the functionality I want.

Thanks again.

VV



 
Old February 1st, 2007, 04:16 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Occasionally, I have clients that want similar things in their applications.

It always takes a lot of time to convince them that they shouldn't want this. A user is used to closing an application by clicking that red X or by other existing ways. That's what they do all day with other web sites and applications. IMO, it's often not necessary to add this functionality yourself, and it will only confuse them.

Since you're not paying me, and since I am not responsible for your application, I won't try to convince you that hard ;) Of course, your reasons for the button may be different. However, it's worth considering if you really need / want this.

BTW, I don't think you can "return to the state it was in just before the user clicked on the link to begin a session". You can close the window, but you'll probably get a confirmation dialog asking if you're sure.

You could keep track of the number of pages a user visited and then do a history.go(numberOfPages) to bring the user back to where they started, but this is difficult if not impossible to implement.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old February 1st, 2007, 11:02 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar:

Thanks for the advice. You know that I take very seriously your comments and suggestions because you have an outstanding track record for helping me.

With regard to stopping the app, I can simply do nothing and let a user red X out, as happens in many other server apps.

I went to that javascript-coder site you mentioned and printed the popuponclick function writeup. I'll check it out.

Thanks again.

VV


 
Old February 1st, 2007, 11:09 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar:

This just occurred to me:

Is there a way to duplicate the functionality of a user click on the red X?

In effect I'm wondering if I can save the user the trouble of navigating his or her mouse to the screen right top and clicking there, and instead providing the same result in a button in the app.

VV



 
Old February 1st, 2007, 01:02 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The close method comes closest (no pun intended) to the normal Close button for the browser.

However, you'll find that sometimes you get a dialog box asking for confirmation. For example, try this:
Code:
<html>
<head>
    <title>Test</title>
</head>
<body>
<form name="frmTest" id="frmTest">
  <input type="button" onclick="self.close();" value="Close" />
</form>
</body>
</html>
You'll get a dialog that confirms you're sure you want to close the window or tab....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old February 1st, 2007, 02:21 PM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar:

I implemented your idea about a selfclose javascript function. Yup, it works just as you and the documentation state: If java does not open the window, a confirmation message appears asking if you really want to do this.

I tried setting several of the window properties to values that I hoped would bypass the confirmation (.closed), and a few other things. I was not able to avoid the message and I am not going to use the javascript window.open functionality.

The situation is worse now because a user would click my page's "Exit App" button and then have to click again on the confirm close window message.

This is not the hotest item on my plate so for now I am going to lay this aside and move on with more development.

So.... Thanks much for your input.

Regards,

VV


 
Old February 1st, 2007, 05:23 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, exactly. That's why I usually recommend not to offer features like this... ;)

There are some tricks where you can assign a reference to this to self.opener to trick the window into thinking it opened itself. However, I believe this no longer works in IE7 and certainly doesn't work in other browsers.

http://www.guyfromchennai.com/?p=18

So, just rely on your user's intelligence to find the normal Close button. Bill and his friends have thought about it for years, so I am sure it's in a logical spot.... ;)

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old February 5th, 2007, 02:42 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Victor,

One trick I have seen work is to self the window's 'opener' property to itself. This tricks the browser to thinking it was opened by another browser, and thus allow you to programmatically close it without confirmation. Here's the modification to Imar's onClick code:

self.opener=self;self.close();

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
using asp.net web user control in asp 3.0 App i_shahid Classic ASP Professional 0 January 8th, 2008 07:32 AM
Turning a regular ASP.NET App into an AJAX ASP.Net donrafeal7 Ajax 2 August 31st, 2007 12:33 AM
post xml data from ASP.NET app to ASP app polekat Classic ASP Professional 2 January 31st, 2007 08:44 AM
System stop responding when I compile web app aremskar VB.NET 2002/2003 Basics 0 February 15th, 2005 09:39 AM
Porting a sa,ple ASP CR viewer app to ASP.NET jhansen42 Crystal Reports 0 August 29th, 2003 10:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.