Prompting Javascript Alert prior to redirection in ASP.NET

My current code is set up to display a message in an update panel while updating:

string jv = "alert('Time OutAlert');";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", jv, true);

It's working well in displaying the message.

However, when I try to redirect the page after showing the message, it loads the next page without displaying the message. What I actually want is for the user to see the message first, click on "ok" and then get redirected to the next page.

string jv = "alert('Time OutAlert');";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", jv, true);
Response.Redirect("~/Nextpage.aspx");

Answer №1

Show an alert using JavaScript and then redirect to a different page:

Execute this script in the HTML file:
ScriptManager.RegisterStartupScript(this,this.GetType(),"redirect",
"alert('Session Expired'); window.location='" + 
Request.ApplicationPath + "Newpage.html';",true);

Answer №2

Attempting to redirect the user before showing a message might not work if the message is running on the client side. However, one way to achieve this is by executing a client-side redirect right after displaying the message.

To accomplish this, you can use the following code snippet:

window.location = "NextPage.aspx";

Answer №3

Everything is Working Perfectly

                string output = "Process Completed Successfully";
                string destination = "/FinalPage.aspx";
                string command = "{ alert('";
                command += output;
                command += "');";
                command += "window.location = '";
                command += destination;
                command += "'; }";
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "alert", command, true);
                

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

The click function is only functioning for the most recently added div, failing to work on all previously appended divs in jQuery

Thank you to all the individuals who take the time to read my post and provide assistance. I am currently working on a select picker that displays the selected options below the select using ajax. However, I have encountered an issue where the 'x&apos ...

Having trouble applying CSS styles to an element using JavaScript

Hello, I have an unordered list with some list elements and I am trying to apply a CSS style to highlight the selected list element. However, the style is not taking effect as expected. function HighlightSelectedElement(ctrl) { var list = document.ge ...

Tips for incorporating a smooth fade in and out effect into images within a Bootstrap 5 carousel

I'm currently working with a Bootstrap 5 carousel and trying to implement a transition effect where clicking the "next" arrow will smoothly fade out the current image before fading in the next one. This is necessary because the images in my carousel v ...

Issue with MERN stack: User not being saved in mongoDB despite lack of errors

Check out the repository at https://github.com/QexleLLC/Otlic After running the frontend with npm start, and starting the backend with nodemon server, everything appeared to be working fine. However, when I tried signing up by going to localhost:3000/sign ...

Could this be a glitch in jQuery, or have I overlooked something important?

Currently, I am utilizing jquery-1.3.2 within an AJAX-driven web application. The jQuery ajax method $.post() is used for sending requests to the server. On the server-side, PHP is utilized to construct an array which is then encoded using json_encode. Su ...

Building an HTML form to generate an array of objects by collecting form data

Hey there, I'm working on an HTML form in React that utilizes form action and FormData. However, when I extract the formData using my method, it shows a structure like this: https://i.stack.imgur.com/nzgLX.png My goal is to have an array of objects ...

Why is my node.js react app failing to detect the index.html file?

Take a look at the app here: git repository The issue I'm facing is that index.html doesn't seem to be properly linked, resulting in: 1) The website not being responsive for mobile devices 2) Lack of a favicon Can you spot any obvious mistak ...

Is it possible to scroll by using the dragenter event?

Looking for a way to achieve incremental scroll up and scroll down using jQuery without jQuery UI? Here's the scenario - I have two divs: <div class="upper" style="height:35px;background-color:red;right:0;left:0;top:0;position:fixed;width:100%;z-i ...

Click on the input to add or remove a value

I have written a code where, on click, I insert an email address into a field. However, what I am trying to achieve is that upon the next click on the same field, it will remove the email if one already exists in the input. Below is my current code snippe ...

Using Aurelia to create a schema form

In my project, I am utilizing Aurelia to create a dynamic form based on a JSON data. The form is being generated from a JSON structure similar to the one shown below: Schema = [{ 'key': 'Name', 'display': 'Name&a ...

Tips for updating an Observable array in Angular 4 using RxJS

Within the service class, I have defined a property like this: articles: Observable<Article[]>; This property is populated by calling the getArticles() function which uses the conventional http.get().map() approach. Now, my query is about manually ...

Navigating without the need for a mouse click

Is there a way to automatically redirect without user interaction? I need the redirection to happen without clicking on anything <script> setInterval(function(){ window.location.replace("http://your.next.page/"); }, 5000); // Redirec ...

JavaScript - Attempting to retrieve data using AJAX

Struggling with extracting data from an AJAX call using jQuery while implementing RequireJS for better maintainability and modularity in my JavaScript. Still new to RequireJS so not entirely sure if I'm on the right track. Just aiming to keep my JS mo ...

Encountering the "test exited without ending" error while using asynchronous forEach loops with tape

My Current Project Edit: I created a repository with a simplified version of the issue I am facing. Currently, my focus is on setting up automated frontend testing using tools like browserstack, selenium-webdriver, and tape. More information about tape ...

Issue with JQuery Ajax button functionality

I am brand new to navigating the world of writing ajax and using a restful api...so please bear with me. On the backend, I have a Laravel 5.2 RESTful API that I'm working with, and my current task involves loading a list of categories using Jquery / ...

Automatically relaunch NodeJS application upon app failure

I am looking for a way to automatically restart my NodeJS (Express) app after crashes with errors. I am familiar with the forever npm package, but all the examples I found were for running the app in development. My goal is to implement this in production ...

Encountering a Peer dependency problem while executing node within a docker environment

Currently, I am utilizing `node-pg-migrate`, which has a peer dependency on `pg`. Here is an excerpt from the library's `package.json` file: "peerDependencies": { "pg": "^4.3.0" }, My attempt to execute the application in Docker involves the fo ...

The count of records in MongoDB by the current month

Recently delving into MongoDB, I found myself in need of a way to retrieve the count of posts made in the current month. Keeping timestamps true in my PlateModel model, it appears as follows: { timestamps: true } The current code snippet in my Controller ...

What is the reason behind the execution of componentDidMount occurring after componentWillUnmount?

I have been exploring the differences between componentDidMount and componentWillUnmout by experimenting with the following code: class App extends React.Component { constructor(props) { super(props); this.state = { name: "", ...

Struggling to navigate web pages with Selenium using Java is proving to be a challenge

I am currently working on using Selenium's HtmlUnitDriver and WebElement classes in Java to automate clicking the "Download as CSV" button on Google Trends. The issue that I am encountering is that the button remains hidden until another settings men ...