.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Close window on Button click in ASP DOT NET.

Posted By:Prasanti Prusty       Posted Date: January 25, 2010    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

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

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 server side 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("")
        End If
    End Sub
End Class



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend