Conformation before closing the Application

Posted by Anilveera under ASP.NET on 1/25/2012 | Points: 10 | Views : 1232 | Status : [Member] | Replies : 5
Hi All,
I had requirement in Asp .net appliction ie... if the user d'nt signoff or logoff then he trys to close the browser ie clicking on 'X' (top right of browser) then i need to show a conformation messasge like "Are you sure you want to close ?" ...
Iam using Masterpage for my application and i tryed the event : "window.onbeforeunload " in my master page its works fine shows an alert(conformation) message. but if i press back button on the browser then also its firing(but it shuold not be) is there any way to full fill my requirement ..plz


Thanks in advance
Veera




Responses

Posted by: Gow.net on: 1/26/2012 [Member] Starter | Points: 25

Up
0
Down
try this

step 1: Add reference ->system.Windows
step 2: add name space using System.Windows.Forms;
and type bellow code in click event
MessageBox.Show("Are you sure you want to close ?", "Information",MessageBoxButtons.YesNo,MessageBoxIcon.Information);



gowthaman8870226416

Anilveera, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anilveera on: 1/26/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for ur valuable response .
i want to fire that message on browser close button ie IE or Firefox('X'/Close button)..

what i mean is.. if the Session("USerid") is active or if containg any value ie.
Session("USerid")="XXX"
at that moment if user trys to close the browse(click in 'X'/Close button) it should give prompt a message "are u sure do u want to close?"..

Anilveera, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gow.net on: 1/26/2012 [Member] Starter | Points: 25

Up
0
Down
refer this

http://stackoverflow.com/questions/2858057/javascript-function-on-web-page-close


gowthaman8870226416

Anilveera, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anilveera on: 1/26/2012 [Member] Starter | Points: 25

Up
0
Down
thank u .. but it is also firing when in clicking back button in browser...it should no be...can we capture that back button event?

Anilveera, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gow.net on: 1/27/2012 [Member] Starter | Points: 25

Up
0
Down
try this coding

<script language="JavaScript">

window.onbeforeunload = WindowCloseHanlder;
function WindowCloseHanlder()
{
//window.alert('Are You Want Close');
var ans;
ans=window.confirm(''Are You Want Close?');
//alert (ans);
if (ans==true)
{
alert('Yes');

}
else
{
alert('No');


}
}
</script>


gowthaman8870226416

Anilveera, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response