1

I use the code below to open a message box:

protected void btnUpdate_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Messagebox", "alert('Record Updated successfully.Note: This tab is now getting close');", true);

        }

How to close the current page after a click on the OK button of this message box?

  • iam using webform not window forms.. – abbas azaad Mar 11 '15 at 10:46
  • @GravCude, unfortunately they said web forms not win forms so .aspx and that doesn't work – MikeT Mar 11 '15 at 10:46
  • I mean current browser tab... – abbas azaad Mar 11 '15 at 10:53
  • Maybe a helpful link: http://stackoverflow.com/questions/16248895/how-to-write-action-on-a-alert-box-ok-button-in-c – Sybren Mar 11 '15 at 10:53
  • 2
    I'm sorry, maybe I should've elaborated. [`window.close()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/close) is a **Javascript** function which closes the current window. – cbr Mar 11 '15 at 10:55
  • 1
    possible duplicate of [Programmatically close aspx page from code behind](http://stackoverflow.com/questions/375406/programmatically-close-aspx-page-from-code-behind) – cbr Mar 11 '15 at 10:56

3 Answers3

0

in web forms you can't close the page, what you will have to do is redirect the page to a different page, and if you add the redirect after the alert it should happen when the alert closes

if you don't know how to redirect a page then this may help aspx page to redirect to a new page however webforms is something i'm still learning myself

Community
  • 1
  • 1
MikeT
  • 5,398
  • 3
  • 27
  • 43
0

Open the current page as popup using window.open() then write a Javascript function in the page such as

<script>
function confirmAndClose()
{
    var conf = confirm("Confirm to close");
    if (conf == true) {
          window.close();
                      } 
}
</script>

then change you server side code to

ScriptManager.RegisterClientScriptBlock(this, "script","confirmAndClose()");
QatQat
  • 15
  • 5
0

Try this,

string message = "alert('Your Approval Has Been Saved Success');self.close();"; ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);

RJay
  • 11
  • 2