I have a web part with button that is clicked upon approval of a workflow. I want to add a JavaScript alert after performing all the button click c# code and then upon closing the alert the browser tab has to be closed.

How can I achieve this?


You should write the javascript code into the page through C# after doing all the other operations you want to do when the button is clicked.

It should work that way:

void Button_Click(object sender, EventArgs e)
    ... your code ...

    ClientScript.RegisterClientScriptBlock(typeof(Page), "myscript", "alert('test');Window.close()", true);
  • I did try your chunk of code.. I was successful in getting the alert, however the Window did not close! – Muhammedh Sep 3 '13 at 5:13
  • window.close might not work correctly in every browser. Try this workaround: window.open('', '_self', ''); window.close(); – Andreas Sep 3 '13 at 7:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.