if you are using IE, tryYourButton.Attributes["onclick"] = "javascript: top.opener=null; top.close(); return false;";