?
Solved

How can I close the current aspx web form?

Posted on 2006-04-26
3
Medium Priority
?
802 Views
Last Modified: 2008-02-01
Hi,

I've an asp.net web app in C#, and I want to have a button which will close the form, thus exiting the application.  Equivalent to the user clicking the X button.

In the button click event I've tried: btn_CloseForm.Attributes.Add("onclick","window.close('FormName.aspx');");

...however, nothing happens the first time this is clicked, and the second time its clicked a messagebox appears asking for confirmation that the user wants to close the form.  I need the form to close immediately on clicking the 'closeForm' button.

Thankyou.
0
Comment
Question by:NAORC
  • 2
3 Comments
 
LVL 15

Expert Comment

by:deepaknet
ID: 16542268
window.close(); does not take any arguments.

BTW, a browser window opened by you can not be closed, without a browser warning. There are unsupported workarounds like setting a window.opener a value and then closing it.

Try this:

btnCloseForm.Attributes.Add("onClick","self.window.opener = 'a';self.close();");

(But this unsupported workaround may not be supported by future web browsers).
0
 
LVL 5

Author Comment

by:NAORC
ID: 16542513
Cheers, this doees close the window without a warning, but only once the button has been clicked twice.  The first click causes a page reload, and the second click closes the page.

Is there a way to do this in one click?

Cheers.
0
 
LVL 15

Accepted Solution

by:
deepaknet earned 1000 total points
ID: 16543083
With a sample HTML like this,

<form>
   <input type="button" value="Close" onClick="self.window.opener='a';self.close();">
</form>

it does respond in a single click.

Did you check the following:

(*) Any other document.click event or event bubbling in effect?
(*) onDblClick being handled?
(*) MouseClick speed  (in Control Panel)
(*) An equivalent in <a onClick="alert('test')">test</a> to ensure that how many times the alert appears.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question