469,951 Members | 2,754 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,951 developers. It's quick & easy.

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 17959
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Jenny | last post: by
5 posts views Thread by jimmy | last post: by
2 posts views Thread by kurt sune | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.