How to close a web page?

G

Guest

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
 
G

Guest

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
 
S

Steven Nagy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top