Click here to Skip to main content
15,896,915 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi frnds,

How to close current tab from code behind in asp.net

I have searched but i am not getting how to do ..

If i use the below code in button click the window is not closing , if i write this code in page load its working ..
C#
Response.Write("<script language='javascript'> { window.close(); }</script>");


My requirement is to close the window after button click from code behind Please tell me guys how to do ..
thanks
mani..
Posted
Comments
F-ES Sitecore 6-Jun-15 15:39pm    
You're not going to be able to do this without the browser showing the user a prompt asking if they want to close the browser. The server code shouldn't interfere or dictate the user's experience, if they want to close the tab they will.
Member 14088131 13-Dec-18 5:44am    
function closeWindow() {
alert("Your Tab is closing.....");
//window.open('', '_self', '');
self.close();
}

Refer - How close Html window when click asp.net button?[^].
C#
protected void ContineButton_Click(object sender, EventArgs e)
{
    this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
}
 
Share this answer
 
Comments
u mani 6-Jun-15 5:53am    
Hi Tadit Dash ,
thanks for reply ,
i have tried but not working , current tab is not closing after a button click .. Please tell me how to do
Do you see any errors on console?
Member 14088131 13-Dec-18 5:44am    
function closeWindow() {
alert("Your Tab is closing.....");
//window.open('', '_self', '');
self.close();
}
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
 
Share this answer
 
Comments
Member 14088131 13-Dec-18 5:44am    
Self.close()




function closeWindow() {
alert("Your Tab is closing.....");
//window.open('', '_self', '');
self.close();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900