Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

closed as off-topic by Muhammad Raja, Benny Skogberg, SPDoctor Sep 3 '13 at 9:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to SharePoint are off-topic here, but can be asked on Stack Overflow." – Muhammad Raja, Benny Skogberg, SPDoctor
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

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);
share|improve this answer
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:'', '_self', ''); window.close(); – Andreas T. Sep 3 '13 at 7:40

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