473,382 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 18180
protected void btnClose_Click(object sender, EventArgs e)
{
// Close;
}
try: Application.Close();
Oct 9 '06 #2
Todd,

1. Usually on the button click you clear out your session variables, and
then redirect (with this.Response.Redirect(anotherPageRelativePath)) 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.close();}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.ClearContent();
this.Response.Write(@"<html>
<head>
<script type='text/javascript' language='javascript'>
<!--
top.close();
// -->
</script>
</head>
<body />
</html>");
this.Response.End();

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.Close();

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
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
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...
4
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...
6
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...
1
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...
4
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...
1
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",...
5
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...
7
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.