Reputation: 3
I simply want to close an aspx Web Form (that is to say to CLOSE THE CORRENT WINDOW).
I saw a lot of explanations that use a Response.Write with Javascript code, but I will not use
them, because I want to know if the C# language offer the possibility itself to close a Web
Form.
QUESTION: How can I close a Web Form with C# code?
Upvotes: 0
Views: 3049
Reputation: 17844
You can't.
C# is used as a server programming language in ASP.NET
C# runs on the web server that has nothing to do with your browser. To close the browser window you should use a clientside language like javascript.
Upvotes: 1
Reputation: 285077
Your C# runs only on the server. It spits out HTML (and maybe JavaScript), then it's done. There's no way to close a window without JavaScript. At most, you might find a C# method that outputs the window.close
JavaScript for you. That doesn't buy you much, though.
Upvotes: 2
Reputation: 40756
That's not possible. C# runs on your server, JavaScript on your client. So the only suitable solution (I'm aware of) is to send a JavaScript close
to the client.
Upvotes: 6