Live Chat Icon For mobile
Live Chat Icon

How to close the browser window on button control click

Platform: ASP.NET| Category: Controls

Method 1. This will cause a postback on button click in response to which we will send some script to close the window.


VB.NET
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  	Response.Write('<script>window.close();</script>')
End Sub

C#
private void Button1_Click(object sender, System.EventArgs e)
{	 
	Response.Write('<script>window.close();</script>');
}

Method 2. This is preferable since there is no postback involved.


Use the Attribute collections i.e use Attributes of button control to add client side JavaScript code
VB.NET 
	 Button1.Attributes.Add('OnClick', 'window.close();')

C#
	 Button1.Attributes.Add('OnClick', 'window.close();');

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.