This is a discussion on How to connect a Database while closing the browser window in asp .net ? within the ASP and ASP.NET Programming forums, part of the Web Development category; How to connect a Database while closing the browser window in asp .net ?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| How to connect a Database while closing the browser window in asp .net ? Generally we can’t get browser close event in C# Using java script we can get that event I am used the following JavaScript for hit the database/code behind while close the browse window. Call the onunload JavaScript method <body onunload="javascript:closeWindow();"> <script language="JavaScript" type="text/javascript"> function closeWindow() { var top=self.screenTop; if(top > 9000) { window.showModalDialog('LogOut.aspx?value=1'); } } </script> In logout page it should hit the database/code behind. But the above code is not working properly. Any one please helps me for this issue ![]() |
| |||
| Here i have given my code ,its works fine for me <script language="JavaScript"> <!-- function closeWindow() { if(document.images){ (new Image()).src="Logout.aspx?value=0"; alert("Log out") } return true; } // --> </script> In Logout.aspx protected void Page_Load(object sender, EventArgs e) { string q1=Request.QueryString.Get("value"); if (q1 == "0") { string connectionString = "Data Source=server;Initial Catalog=TestDB;Persist Security Info=True;User ID=test;Password=pass "; SqlConnection sqlconn=new SqlConnection(connectionString); sqlconn.Open(); SqlCommand sqlcomm = new SqlCommand("INSERT INTO [test].[dbo].[Persons]([LastName],[FirstName],[Address],[City]) VALUES ('test' ,'test' ,'test','test')", sqlconn); sqlcomm.ExecuteNonQuery(); sqlcomm.Dispose(); sqlconn.Close(); } } |
| |||
| hi..... i have made some changes in the code..... it will help u.... ![]() <script language="JavaScript"> <!-- function closeWindow(evt) { var e = (window.event) ? window.event : evt; if (e.clientX < 0 && e.clientY < 0) { if(document.images) { (new Image()).src="logout.aspx?value=0"; alert("logout") } } return true; } // --> </script> </head> <body onunload="closeWindow(event)" > |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/asp-asp-net-programming/2176-how-connect-database-while-closing-browser-window-asp-net.html | |||
| Posted By | For | Type | Date |
| Digg / Programming / Upcoming | This thread | Refback | 07-20-2007 08:12 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to connect C with DataBase? | yuva | C and C++ Programming | 4 | 03-21-2008 09:35 PM |
| Need to close parent window after closing child window. | S.Vinothkumar | ASP and ASP.NET Programming | 6 | 11-05-2007 06:08 AM |
| Is it possible to close the parent window (main web browser window) from a child win | gp_logesh | HTML, CSS and Javascript Coding Techniques | 1 | 10-29-2007 04:53 AM |
| Can I connect to a Microsoft Access database without a DSN | itbarota | PHP Programming | 0 | 09-11-2007 12:30 AM |
| Can anybody tell me Browser Differences in window.opener Behavior | kingmaker | HTML, CSS and Javascript Coding Techniques | 2 | 07-24-2007 12:52 AM |