In this post we will discuss how we can close browser in button click in Asp.Net. Also you can check out my previous posts on:
- Show confirmation dialogbox using JavaScript in Asp.Net
- Difference between primary key and foreign key in SQL server
- Difference between Server.Transfer and Respose.Redirect in Asp.Net
There are two approaches we can close the browser in button click. In both the approaches it will ask for a confirmation message.
Approach-1:
In the Page_Load write the code like belwo:
protected void Page_Load(object sender, EventArgs e)
{
btnCloseBrowser.Attributes.Add("onclick", "self.close()");
}
Here btnCloseBrowser is the button ID.
Approach-2:
You can also write the below code in the button click event like below:
protected void btnCloseBrowser_Click(object sender, EventArgs e)
{
Response.Write ("<script>self.close() ;</script>");
}
In both the case it will ask for a confirmation message like below:
Once you click on OK, it will close the browser.
- Show confirmation dialogbox using JavaScript in Asp.Net
- Difference between primary key and foreign key in SQL server
- Difference between Server.Transfer and Respose.Redirect in Asp.Net
There are two approaches we can close the browser in button click. In both the approaches it will ask for a confirmation message.
Approach-1:
In the Page_Load write the code like belwo:
protected void Page_Load(object sender, EventArgs e)
{
btnCloseBrowser.Attributes.Add("onclick", "self.close()");
}
Here btnCloseBrowser is the button ID.
Approach-2:
You can also write the below code in the button click event like below:
protected void btnCloseBrowser_Click(object sender, EventArgs e)
{
Response.Write ("<script>self.close() ;</script>");
}
In both the case it will ask for a confirmation message like below:
Once you click on OK, it will close the browser.