Looking to display a dialog box using JavaScript

Hello everyone, I have a web form with a button that triggers a data backup process when clicked. Here is the JavaScript code I am using:

<script language="javascript" type="text/javascript">
   function showPleaseWait() {
       document.getElementById('PleaseWait').style.display = 'block';
   }
</script>

<asp:Button ID="btnTakebackup" runat="server" Text="Take Backup"  Enabled="true" 
   onMouseDown="showPleaseWait()" CausesValidation="false" />

<div id="PleaseWait" style="display: none;">"Please Wait Backup in Progress.."</div>

Currently, I am utilizing a button for conducting backups.

My goal now is to display a message in the btnTakebackup_Click() event indicating whether the backup was successful or not. I tried using

Response.Write("<script>alert('abcd');</script>");
in the btnTakebackup_Click() event. However, the issue I am facing is that I want to show the page as well, but instead, only a white background is displayed.

Thank you in advance...

Answer №1

In order to display a message box alert, you must be able to generate a new script that can be written directly to the response stream:

var customScript = 
    "<script type=\"text/javascript\">" +
    "alert(\"Please wait, process in progress...\");" +
    "</script>"
Response.Write(customScript);

Even though this may not be ideal, it is sometimes deemed as "essential".

Answer №3

Are you considering using an alert for this situation? Keep in mind that alerts can lock up the entire browser, not just the tab where your page is located. Think about whether your users actually need to actively acknowledge the success of the backup by clicking 'ok', or if they can simply be informed of it...

One suggestion is to have a div on the page displaying "Backup successful". You can control its visibility with a boolean property BackUpSuccess, which you can set to true in the code mentioned earlier.

<div id="backUpSuccess" <%=BackUpSuccess ? "" : "style='display:none;'"%>>
    Backup was successful
</div>

You can customize the styling of this div in your .css file to ensure it stands out visually.


If you still want an alert, you could consider running some JavaScript on page load to check the content of a hidden input, set server-side in a similar manner...though executing JavaScript on page load can be tricky unless you're using jQuery, in which case it's much simpler.

Answer №4

After reviewing your question, it seems that although the data backup process is initiated when the button is clicked, the alert message does not appear immediately upon clicking the button. This issue occurs because the JavaScript function is being called within the button click event, which will only execute after all the code within the button click event has been processed. To address this, I recommend adding a JavaScript function directly in the .aspx source page and calling this function as illustrated below:

<script ...>
function xyz()
{
alert('Please Wait');
}
</script>

and in the button declaration

<asp:button id='btn_submit' runat="server" OnClientClick="return xyz();" />

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

Protractor appears to have a lack of patience

Currently utilizing Protractor by Bruno Baia v0.9.2 Selenium Webdriver v3.0.1 Selenium.Webdriver.ChromeDriver v2.27.0 and encountering an issue. I am logging in from a non-Angular page, however when I navigate to the first Angular page of my application, I ...

Similar to Java's Robot class, C# offers the functionality of programm

I'm looking for the C# equivalent of Java's Robot class to control mouse pointer movements. Since the Actions class cannot be directly used for keyboard and mouse functions, I need a way to visually move the mouse pointer in Selenium using C#. Fo ...

Creating a full-screen overlay that is mobile-friendly using Javascript and CSS

I'm currently developing a jQuery lightbox plugin that needs to work seamlessly on both mobile devices and desktop computers. The main issue I'm facing is with the full-screen overlay effect. Most resources suggest using position: fixed or backgr ...

Unable to retrieve Vuex state within a function

Currently, I am developing a Laravel+Vue application where Vuex is used for state management. While working on form validation, everything seems to be progressing smoothly except for one particular issue that has me stuck. The problem arises when I attempt ...

Can GET or POST variables be transmitted to external JavaScript?

Is it possible to pass a variable to an external JavaScript file? For instance: Suppose I have the following code: <script type="text/javascript" src="gallery.js"></script> I'm curious to know if it's feasible to pass an argument ...

Navigate to the selected row in GridView

I am currently working with a GridView that has a fixed header and 10 rows that users can update with new information. The GridView displays only 3 rows at a time along with a vertical scrollbar. My goal is to automatically scroll the GridView to the sele ...

Changing an image depending on the visibility of another image can be accomplished by using JavaScript to

On a webpage, I have a logo that I want to change based on the visibility of another image. The other image is part of a list that fades between images and repeats. The goal is for Logo1 to display when a specific image is shown, and then switch back to L ...

What is the method to execute a function on the existing page when the browser goes back?

DESCRIPTION: In order to create a seamless transition between pages on my website, I have implemented a white opaque overlay layer that fades in and out. When a user clicks on a link, a script is activated which prevents the default behavior, fades the inv ...

Utilizing fluent-ffmpeg in nodejs and express to effortlessly download a video

I've been recently tackling a side project that involves downloading videos from Reddit. The tricky part is that the video and audio are stored in separate files, requiring me to merge them before being able to download them onto the client's dev ...

Dividing an Image into segments using Javascript

I'm currently working on a basic Jigsaw puzzle project. To achieve this, I am required to divide the image I've selected into 20 separate pieces. I was wondering if there is a method in Javascript that can automatically cut an image into 20 equal ...

Is it possible to incorporate a modal backdrop into a Kendo window?

Utilizing the Kendo UI framework and utilizing the window UI WIDGET, you can refer to Can a modal background be added in light grey color similar to the feature available in Jquery UI dialog at http://jqueryui.com/dialog/#modal ? Is it possible to make t ...

What is the best way to add an image using a textarea or HTML editor?

Every time a user inputs text into the textarea, it works fine. However, issues arise when they try to insert an image... For instance, if they input this code in the textarea (Thumbnail image linked code) <a href="http://www.ultraimg.com/image/1V6n"& ...

Expecting a declaration statement for exporting React

When attempting to export my component, I encounter an error in my editor stating export declaration statement expected Here is the code snippet: export Header from './Header/Header'; However, if I modify it like this: export {default as Head ...

Creating a PHP JSON response that incorporates an HTML layout is a dynamic

I'm having some trouble with a certain issue: I am attempting to develop a jQuery/AJAX/PHP live search bar. Although I am successfully calling search.php, the response displayed in the console always includes the contents of my master.php file (which ...

Adjusting the projection matrix parameters in Three.JS

My goal for this project is to manually adjust the parameters of the projection matrix. For instance, I would like to have the ability to do something similar to the following: camera.projectionMatrix[15] = 1; Is there a way to achieve this in Three.JS? ...

Employ AJAX to dynamically refresh the page whenever a new row is inserted into the table

Currently, I am in the midst of learning AJAX because it is necessary for a project I am working on. The aim is to refresh a feed in real-time whenever a new row is added to a MYSQL table. While I have successfully achieved this using node.js, my client&ap ...

Troubleshooting a Tiny Bottom Sheet Problem in react-native

On my page, I have a bottom sheet that takes up 3/4 of the space. Then, within that bottom sheet, I open another bottom sheet that only occupies 1/4 of the space (without closing the first one). ...

Steps to resolve the issue of ng-click not functioning in a recursive directive template

I've encountered an issue with using ng-click within the template of a recursive directive. Here is the code snippet: https://jsfiddle.net/qxz7506n/ While clicking the 'root load more button' works fine, the 'child load more button&ap ...

Mastering the use of JavaScript callbacks without relying on the jQuery library

I've been working with jquery and javascript for quite a while now. I rarely code in pure javascript, but this time I need to understand callbacks in javascript. It seems like a simple case, but I just can't wrap my head around it. I not only wan ...

Transferring data from SocketIO to Vue.js

Is there a way to effectively transfer data results received from socketIO to the Vue instance? Below is my current code implementation: let socket = io(); let users; socket.on('user-connected', (data) => { users = data.count; }); socket ...