views:

152

answers:

4

I have a silverlight application and I want to capture the close event of the browser. So what I did, in my .aspx page i have this code

function closeIt() {
        return "Any string value here forces a dialog box to \n" +
     "appear before closing the window.";
    }


    window.onbeforeunload = closeIt;

If this functions triggered, a popupwindow will appear, you have 2 buttons OK and CANCEL.

Is there a way in silverlight or in server side to get the value of what the user clicks?

Thank you

A: 

Why don't you use MessageBox ? here's code example:

MessageBoxResult result =  MessageBox.Show("Text","Title",MessageBoxButton.OKCancel);
if (MessageBoxResult.OK==result)
{

}
else if (result == MessageBoxResult.No)
{

}

this will get you a popup window with OK and CANCEL window with pretty easy way to determine whether user clicked Ok or no.

tchrikch
The purpose of it was to capture the close event of the browser.
xscape
A: 

I am not sure I totally understand your question, it looks like you are writing javascript. But your subject is silverlight. Anyway....

The simplest way is to leverage Html Confirm either in silverlight:

bool result = System.Windows.Browser.HtmlPage.Window.Confirm("Really..?"); 

or in straight JavaScript:

var result = window.Confirm("Really...?");

To get the value to the server you can store the value in a hidden text field and post it to the server.

Dan
A: 

The answer is pretty much the same as my other answer to your prior question re window.close.

When the user selects Cancel absolutely nothing happens. If they select OK then your Application_Exit will run.

AnthonyWJones
thank you but thats what I wanted to capture the cancel event.
xscape
A: 

same solution on my previous question

http://stackoverflow.com/questions/3456591/silverlight-4-f5-refresh

xscape