开发者

Silverlight 4: OnBeforeUnload

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" +
     "ap开发者_开发技巧pear 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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜