What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 42713 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > Close window on Button click in ASP DOT NET. ...
Chikul

Close window on Button click in ASP DOT NET.

 Code Snippet posted by: Chikul | Posted on: 1/25/2010 | Category: ASP.NET Codes | Views: 3830 | Status: [Member] | Alert Moderator   


To close a browser window there is only one Way i.e to add javascript.

Below are the two methods of making a browser window (page) close.

Method 1 : On page load add the script to the button onclick attribute . It will occur a bit faster.

Method 2 : If User wants to validate some Process before Window close, Its better to use Method 2 ,Because using the first Method no serverside code will get executed.
Here On Button Click Use the Script to close the window.
So Before closing the window we can Validate the Process in the Applications

Codes :


Partial Class Default5

Inherits System.Web.UI.Page

'Method 1 : On Page_Load add the Attribute
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
btnClose.Attributes.Add("onclick", "window.close();")
End Sub

'Method 2 : on Button Click Use the Script
Protected Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
If Page.IsValid Then
Response.Write("<script language='javascript'> { window.close();}</script>")
End If
End Sub
End Class

Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 6:12:44 AM