473,778 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to close a web page?

Hey guys,

I've developed a C# Web Form using Visual Studio 2005. I can't quite
figure out how to exit the form though??? On my form, I have a button which
says "CLOSE". I'd like for someone to be able to click that, and then have it
automatically just exit out of the application. How do I do that?

This is my on event procedure, what should be in here???

protected void btnClose_Click( object sender, EventArgs e)
{
// Close;
}

Thanks!

Todd
Oct 9 '06 #1
3 18219
protected void btnClose_Click( object sender, EventArgs e)
{
// Close;
}
try: Application.Clo se();
Oct 9 '06 #2
Todd,

1. Usually on the button click you clear out your session variables, and
then redirect (with this.Response.R edirect(another PageRelativePat h)) to
another - say, home - page.

2. If you opened your application in a new window with javascript, then you
could just use <input type='button' value='Close' onclick='if (confirm('are
you sure?')){top.cl ose();}return false;'/instead of your asp:button. This
will close the opened browser window without even hitting the server. You
will not have a chance to clear out session (and/or cache) variables,
however. You can change the confirmation text or remove it altogether, if
needed.

3. If you need to do both: clear the variables and close the browser window,
then you need to use asp:button and on its server click event clear all
necessary variables and change Response to something like:
this.Response.C learContent();
this.Response.W rite(@"<html>
<head>
<script type='text/javascript' language='javas cript'>
<!--
top.close();
// -->
</script>
</head>
<body />
</html>");
this.Response.E nd();

Both 2. & 3. assume that javascript is enabled - otherwise it will not work.

hope this helps
"Todd Jaspers" wrote:
Hey guys,

I've developed a C# Web Form using Visual Studio 2005. I can't quite
figure out how to exit the form though??? On my form, I have a button which
says "CLOSE". I'd like for someone to be able to click that, and then have it
automatically just exit out of the application. How do I do that?

This is my on event procedure, what should be in here???

protected void btnClose_Click( object sender, EventArgs e)
{
// Close;
}

Thanks!

Todd
Oct 9 '06 #3
try: Application.Clo se();

I think he said web form, not windows...
And that will cose the entire app, not just one form.
>>
Check the other answer about javascript. What you could do is in your
server side event handler, write out some javascript with
Response.Write to close the form.
Its not uncommon to have a span or label as a server side control where
you can place some javascript for when its needed.

Closing the form is client side work, not server side work.
You need to differentiate your technologies. ASP.NET for server side.
Javascript and HTML for client side.

Hope this helps!
Steven

Oct 9 '06 #4

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

Similar topics

7
5177
by: Jenny | last post by:
I open page 1 and page 2 from main page. I want to close page 2 from page 1 after I finish processing some work in page 1. Does anyone know how to do that? Thanks, Jenny
28
14260
by: PerryC | last post by:
Anyone know how to auto close the parent / opener window without confirmation? I have tried: <script> opener.window.close() </script> ----I put it in the child html page, and nothing happen!!---
4
34888
by: GrantS | last post by:
I am having a problem closing a popup window opened modally. When I try to close the window (when the user hits save button and the data has been processed), the Popup window opens as a full screen as a new window. The original window plus the Modally opened Pop remain in a separate window. What I want to do is close the popup and return to the original window with its view state maintained. The control use to fire the popup window...
6
4606
by: No_Excuses | last post by:
All, I am interested in reading the text of a web page and parsing it. After searching on this newgroup I decided to use the following: ******************************* START OF CODE ************************ String sTemp = "http://cgi3.igl.net/cgi-bin/ladder/teamsql/team_view.cgi?ladd=teamknights&num=238&showall=1"; WebRequest myWebRequest = WebRequest.Create(sTemp); WebResponse myWebResponse = myWebRequest.GetResponse();
1
1465
by: Bob | last post by:
Is this a good way to close DB Connection in ASP.NET? I've been trying to come up a way to close DB connection automatically (or sort of) in my ASP.NET application without having to write the close() method everywhere. Every web page in my application needs to call the database, and all DB access and SQL Command code are wrapped in a separate class (called DBAccess below). I don't want to open and close the connection within every...
4
1921
by: louise raisbeck | last post by:
I have this scenario (simplified) function addnewdata () { check for partial match already in db for information entered by user if (partialmatch succeeds) { open new window aspx page (using javascript) with a datagrid of these partial match records (by doing a sqlcommand using some query string values taken from opener data entered) *** }
1
33184
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X", I'll need to kill the session. Now, with the onbeforeunload event, I can handle this quite easily in IE, but in FireFox, it's another matter. For one thing, FireFox seems to empty out its event object on a page unload, so it's very hard to track...
5
34368
by: jimmy | last post by:
Hi all, I want to capture the event when the browser's close button is clicked in an html page. I tried using the event.ClientX and event.ClientY property in the body unload event, and this helps to recognise whether the close button is clicked( also differentiates whethet refresh was clicked). The problem arises whenever i try to close the window by resizing it or by right clicking at the bottom of the page and then closing it. Can...
7
3356
by: tapanreddy | last post by:
I am looking to perform an action when we close the window using the close tab at the top of the screen. I know how to do it using a close button but I was wondering if there is way to achieve the above. Waiting for some suggestions Thanks
2
6760
by: kurt sune | last post by:
Hello, I have a weird problem, I hope someone can explain this for me. I have a webpage using masterpage. In it I create a popup window using this code: Dim js As String = "<script language=javascript>" js &= "var newWin = window.showModalDialog('InkommetVi.aspx" js &= "',null,"
0
9628
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
10292
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
10122
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...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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
5368
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...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
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.