Silverlight 4: The Preceding Departure

Is there a way to capture the close event of a browser in Silverlight application? I have implemented the following code in my .aspx page:

function confirmClose() {
    return "Any message here will prompt a dialog box \n" +
            "before closing the window.";
}

window.onbeforeunload = confirmClose;

When this function is triggered, a popup window with OK and CANCEL buttons will appear.

Is it possible to retrieve the value of what the user clicks either in Silverlight or on the server side?

Appreciate any help. Thank you.

Answer №1

I'm not entirely certain I grasp the gist of your query, it seems like you're working with javascript. However, your focus is on silverlight. Anyways...

The easiest method is to use Html Confirm either within silverlight:

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

or in regular JavaScript:

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

To transmit the value to the server, you can save the value in a hidden text field and send it to the server.

Answer №2

Ever thought about using MessageBox in your code? Here's an example of how you can implement it:

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

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

}

By incorporating this, you'll have a convenient popup window with options for OK and Cancel, making it simple to determine the user's selection.

Answer №3

This answer mirrors my previous response to your query about window.close.

If the user clicks Cancel, there will be no action taken. However, selecting OK will trigger the execution of your Application_Exit function.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to utilize CSS to alter the header content when the window is minimized?

I am currently experimenting with replicating a website design from a popular clothing brand to enhance my knowledge of HTML and CSS. I am curious to know if it is possible to modify the header content when the window size is reduced, either through CSS al ...

Leveraging the power of Notepad++

When I attempt to use Notepad++ for Javascript, it isn't functioning as expected. Instead of displaying the proper outcome on the web page, all I see is a jumbled mess. Currently, I am using version 6.6.7 of Notepad++. Here's my process: Typ ...

Node.js fails to acknowledge Ajax requests

I am creating a secure webpage specifically for an Ajax request. Below is the code for the simple request: window.onload = loaded; function loaded(){ var xhr = new XMLHttpRequest(); xhr.open('GET', '/data_annotations', true); ...

JQuery - Issue with setTimeout Function on Mouseleave Event

I am currently facing an issue with the script below. The goal is to display a div instantly when hovering over a specific area, and then make it disappear after a certain amount of time when leaving that area. Everything works perfectly, except if the mou ...

Automatic File refresh in Javascript without page reload

My webpage includes a javascript file that is called in the head tags of the document. I need this javascript file to reload every 30 seconds. In my research, I found issues with pulling a locally stored copy of the file and potential cross-browser compat ...

Tips for preserving additional information in a form by selecting "add more" option

Recently, I encountered a challenge with a form on my website. Whenever a user fills out a few fields and clicks "Add", the data transitions into an HTML element. Subsequently, the form partially clears for more data input. Now I'm faced with the dil ...

What methods can be used to block the input of non-numeric characters in a text field?

I stumbled upon this particular inquiry. Although, the majority of responses involve intercepting key presses, checking the key code, and halting the event if it does not match an acceptable key code. However, there are some issues with this approach. ...

What causes the slowdown in mapping a lone object with Automapper compared to mapping a larger quantity such as 10 or 100?

Code for Data Analysis: using System; using System.Collections.Generic; using System.Diagnostics; using AutoMapper; namespace Automapper { class Program { private List<Customer> _customers = new List<Customer>( ...

Implementing default header and footer with Angular's ui.router

When dealing with ui.router modules, I have identified three different methods for setting a default header and footer for every view: DEFAULT HEADER <CONTENT> DEFAULT FOOTER 1. Using ng-include - inserting your header/footer in the initial .html ...

Looking for an Effortless Loading jQuery Image Slider or: Unleashing the Power of cross-slide

I am in need of assistance with implementing lazy loading for images in a jQuery slideshow that pulls from Flickr. Although everything is running smoothly, I would like to optimize the image loading process by only loading them on demand. Currently, I am ...

Toggle between list elements using the inner text of the elements with jQuery

My issue lies in figuring out why my filter function isn't properly working for toggling li elements. JavaScript: $("#searchbox1").on("keyup", function() { var value = $(this).val().toLowerCase(); $("#menulist li") ...

The absence of $_POST results in the values being stored in $GLOBAL instead

Ever since I reinstalled my OS, I've been encountering a peculiar $_POST issue. When I returned to one of my side projects, I realized that all my POST requests were not functioning properly, despite having worked before. I've observed that all ...

What could be the reason for not receiving any response from my Firestore query?

Hey there! I'm delving into the world of Firebase for the first time and just set up the Firestore emulator. I've added some data that I want to fetch in my Nextjs app. Once I initialized firebase, this is what my component code looks like: funct ...

The HTML required attribute seems to be ineffective when using AJAX for form submission

Having trouble with HTML required attribute when using AJAX submission I have set the input field in a model Form to require attribute, but it doesn't seem to work with ajax. <div class="modal fade hide" id="ajax-book-model" a ...

What is the best way to measure the loading time of a "Loading Screen" page using Jmeter and Selenium?

Once a file is uploaded to the website, a loading screen appears depending on the file size. I am interested in measuring how long this loading screen remains active. As a novice in jmeter and programming, I'm unsure if there's a more efficient m ...

Styling the NavDrawer button and navigation bar in React Native Router Flux

Currently in React Native Router Flux, I have a working NavDrawer component that utilizes react-native-drawer. The default hamburger menu icon on the left side of the navigation bar is what is currently displayed, but I am looking to swap it out for a cust ...

Decoding a JSON object in node.js

{"__v":0,"_id":{"$oid":"55f13d34258687e0bb9e4385"},"admin":true,"email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3d6ded2c3dfd682f3d4ded2dadf9dd0dcde">[email protected]</a>","last_login":"11:25:24 AM","name ...

JavaScript Function Causes Applet's URLConnection.connect to Fail

My website features a Java Applet that needs to connect to the server. Interestingly, it successfully connects in JApplets @Override init(), but when called by JavaScript, it fails to do so. final URL url = new URL(SERVER_URL + action); System.out.println ...

Tips for obtaining the dynamically loaded HTML content of a webpage

I am currently attempting to extract content from a website. Despite successfully obtaining the HTML of the main page using nodejs, I have encountered a challenge due to dynamic generation of the page. It seems that resources are being requested from exter ...

managing data in an uncomplicated manner

In my website, users can select animals from a database without the page reloading. For example, under the category "Brown Animals," a user might choose "kittens" by checking a checkbox. Later, when browsing through "Cute Animals," if "Kittens" is displaye ...