0

I have a specific requirement, which is when the user clicks on a button, I want to save some data then close the page.

I already did the saving function,

but I don't know what should I do to make the close option.

I mean that after saving, the page should automatically close

how can I achieve that please?

I am using asp.net with windows server 2003 on IE 8

user2226785
  • 479
  • 8
  • 16
  • 1
    Take a look at this [thread](http://stackoverflow.com/questions/375406/programmatically-close-aspx-page-from-code-behind) – Andrei Mar 31 '14 at 14:28
  • 3
    Never close a browser page you didn't yourself open. You can redirect somewhere else, but don't close the user's browser window. – Joel Coehoorn Mar 31 '14 at 14:33
  • @JoelCoehoorn it is a required function from my boss – user2226785 Mar 31 '14 at 15:55
  • @Andrei that thread helps, type an answer to accept it – user2226785 Mar 31 '14 at 15:56
  • I understand that sometimes you have to follow orders. But you can also push back first... unless you first opened this window yourself via javascript, closing the window creates a horrible user experience, because this can make the entire browser just go away. It will help your case if you can offer an alternative: redirect to a different page, with clearly labeled "close window" text and perhaps a small menu to other areas of your site. – Joel Coehoorn Mar 31 '14 at 15:57
  • @JoelCoehoorn I would do that but actually this is my 7th day in work. So, I don't want to upset my boss, who I have never seen bty, by something he already ordered. It would be like, "this is your first week and you start intervention in our business". I myself don't like the close too :) – user2226785 Mar 31 '14 at 16:00
  • @user2226785, that would be a link-only answer, which is no good – Andrei Mar 31 '14 at 16:05

1 Answers1

0

In your button click event you can call the save data method and then at the end of the saving method put below line of code to close the page

ClientScript.RegisterStartupScript(typeof(Page), "closePage", "<script type='text/JavaScript'>window.close();</script>");
Damith
  • 62,401
  • 13
  • 102
  • 153