I'd like to have the standard SharePoint save button SharePoint:SaveButton To use JavaScript to close the open window (this is not a modal, but the actual window or tab) when it is finished. Is this possible? I'd prefer not to use jQuery for something so simple if possible.

2 Answers 2


I replaced the SharePoint save button with the following HTML/JavaScript. It even has an alert.

<input name="Submit1" type="submit" value="Save Changes" id="Submit1" style="width:140px" onclick="javascript: {ddwrt:GenFireServerEvent('__commit')}; window.alert('Item updated.') ; window.close();"  />

This button saves the SharePoint item, sends an alert, then closes the window after the alert is acknowledged.

Here is a simple Cancel button which does not redirect, but will close the window instead.

<input name="Button1" type="button" value="Cancel" style="width:140px"  onclick="javascript: window.close();"/>
  • I tried this solution but it is not working for me.. even alert is not getting fired... can you please provide me any alternate solution if you have one .. Jan 23, 2017 at 10:41

This is what I used. Bear in mind this logic works when the page it is on has been opened up in a new tab. Also note I am not doing any javascript alert for telling the user (because it's implied in button text value).

Enclosed this on the page that is opened in a new window/tab:

HtmlGenericControl btnClose = new HtmlGenericControl("input");
btnClose.Attributes["type"] = "button";
btnClose.Attributes["style"] = "text-align:center; font-size:13px; font-color:#000; font-weight:bold";
btnClose.Attributes["onclick"] = "window.open('', '_self', ''); window.close();";
btnClose.Attributes["value"] = "Click here to close this window or tab.";

Added the event for sharepoint since javascript is so finicky in SharePoint:

protected void btnClose_Click(object sender, EventArgs e)
   string script = "<script type='javascript'>window.open('','_parent',''); window.close();</script>";
   Page.ClientScript.RegisterClientScriptBlock(GetType(), "Register", script);

The window.open that is used is a workaround to ensure most browsers will accept.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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