in our Silverlight app we open up a new Silverlight control hosted in a new HTML page and things work great as long as the user does not hit the browser close button before the secondary page loads. Then both browser windows disappear with no warning. I tried writing Javascript to handle the onbeforeunload but even this was not called. The idea was to warn the user that this action could be bad. So I then write a real simple sample app to repro the issue and here are the ni-lites:
add a button to the parent page:
HtmlPage.Window.Navigate(new Uri(String.Format("TestControlTestPage.aspx"),
UriKind.Relative), "searchresults",
"directories=no,location=no,menubar=no,status=yes,toolbar=no,resizable=yes");
This opens a new HTML Page hosting a new Silverlight control , newControl and in here I simulate the situation in our app where we must load some stuff from the server as follows:
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
System.Threading.Thread.Sleep(10000);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
}
So there is delay before the loaded method is called, and if I press the X (Close) before the page loaded is called then both windows disappear.
as mentioned above I also have a tried adding javascript for the onbeforeunload but this was not called. Pretty ugly any ideas would be appreciated