IT Community - Software Programming, Web Development and Technical Support

How to connect a Database while closing the browser window in asp .net ?

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 ?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-18-2007, 10:58 PM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Question How to connect a Database while closing the browser window in asp .net ?

How to connect a Database while closing the browser window in asp .net ?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-19-2007, 12:43 AM
bluesky bluesky is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 201
bluesky is on a distinguished road
Default Re: How to connect a Database while closing the browser window in asp .net ?

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-19-2007, 02:29 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How to connect a Database while closing the browser window in asp .net ?

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();
}
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-20-2007, 03:14 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: How to connect a Database while closing the browser window in asp .net ?

hi.....


its working fine.... but i have an issue..

some times it gets fired when we refresh the page...

could u pls help me...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-20-2007, 03:17 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Thumbs up Re: How to connect a Database while closing the browser window in asp .net ?

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)" >
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-20-2007, 03:20 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Red face Re: How to connect a Database while closing the browser window in asp .net ?

hi...... great work......


its working fine, but only in IE, not in firefox

help.......... me....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -7. The time now is 09:45 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0