In every instance, the Javascript function will trigger the .asp method located within the else clause

Currently, I am working on a web page using ASP.NET and have created a sessionTimer JavaScript function with an "if/else" conditional statement. The function retrieves a variable from the config file by calling an ASP.net function in the if clause, and then calls another ASP.net function in the else clause to perform additional actions. However, the issue I am facing is that this code always ends up calling the .ASP function within the else loop consistently. Can you provide insights into why this might be happening?

var sessionTimeout = 1;
function Timerfunction()
{
     sessionTimeout = sessionTimeout - 1;
     var sessiontimoutValue = '<%= GetSessionTimeout() %>';

     if (sessionTimeout >= 0) {    
         window.setTimeout("Timerfunction()", sessiontimoutValue);
     }
     else {
         var result = '<%= Timer_Timedout() %>'
     }
}

Answer №1

When using the <%= %> tags to insert values from the server into the response, you are essentially injecting that value directly into what is sent to the client. For example, if you are inserting the results of the function Timer_Timedout(), it will be included in the response without having to make another request to the server.

This means that whatever is inside these tags will be evaluated and executed when the page is requested, regardless of any client-side logic in the javascript. There is no need to go back to the server to fetch these values, as they are already included in the initial response sent by the server.

If you find yourself needing to check the session status or perform some other action based on client-side logic, you may need to consider using ajax or making additional requests to the server to get the relevant information.

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

Prevent the instant spread in the AJAX success function

Here is a snippet of my code: $(document).on('click', '[data-submit-form]', function (event) { var form = $(this).closest('form'); $.ajax({ url : form.attr('action'), type : 'post' ...

Navigating through route parameters and application logic

There is an endpoint / which may receive different get parameters for oAuth and logging in to an app. A function called queryAction has been created to handle these requests. Platforms like express can route at the path level but not the res.query level, ...

Filter the object by its unique identifier and locate the entry with the highest score

I'm currently working on figuring out the proper syntax for sorting an object by ID and then identifying the highest score within that ID array. While I've managed to sort the object up to this point using conditionals and the sort() method, I&ap ...

Tips for clearing the sessionstorage upon browser refresh without removing data when clicking the back button in the browser

I am looking to clear the session storage only when the page is refreshed, without affecting the browser's back button functionality. I want to achieve this using AngularJS/JavaScript. Currently, I am storing data in sessionStorage on a back button c ...

Django has a tendency to run view functions repeatedly after a form submission, even if the client has only submitted the form

I am facing an issue with uploading a user's image to the server in Django (version 1.8) for processing. Despite ensuring that the client only submits the form once, the backend seems to execute the related view function multiple times, leading to a 5 ...

What sets apart importing crypto from 'crypto' as opposed to simply using crypto in Node.js?

For my upcoming Node project, I'm considering using crypto to obtain a UUID. After some research, I discovered that I can achieve this by utilizing crypto and that it is already a declared variable without the need for importing it. So there are two o ...

What is the process for updating a property in Inertia.js and Vue.js?

I am attempting to modify the list property in Vue.js using Inertia.js: props: { list: { type: Object, default: {} } }, updateTable(filters) { axios.post(route('updateList'), filters) .then(r => { ...

CORS headers not functioning as expected for Access-Control-Allow-Origin

Can someone help me figure out how to add Access-Control-Allow-Origin: 'http://localhost:8080' in Node.js and Express.js? I keep getting this CORS error: Access to XMLHttpRequest at http://localhost:3000 from origin 'http://localhost:8080&ap ...

Tips for easily consolidating JavaScript functions into a single file

I am currently dealing with a situation involving some basic IF / show/ hide scripts. I have successfully managed to get each individual script working on its own. However, when I try to combine them, they seem to conflict with each other and I am struggl ...

The functionality for inserting data via Ajax in WordPress is failing

Greetings, I am currently in the process of developing a popup plugin for WordPress that involves inserting data into a database using AJAX. Everything in my code is functioning correctly up until the jQuery section, where the data fails to insert into the ...

Basic animation feature malfunctioning

So, I'm really new to this whole HTML5 canvas thing and I'm trying to make a pixel move across the screen with an additive tail behind it. The idea is for the tail to scroll away once it reaches a certain point while the pixel continues moving. I ...

I'm unsure why process.env.BACKEND_URL displays as undefined in the console, but appears correctly in a button within my Next.js application

I've encountered a challenge with environment variables while working on a Next.js project. In my Home component, I'm attempting to print the value of process.env.BACKEND_URL to the console and display it within a button. 'use client' i ...

Tips for preserving textarea content upon clicking outside the area with the help of ajax

I am new to using the Froala editor and I am currently working on a feature where I need to save text in the textarea of the editor when the user clicks outside of it using Ajax. The ID of the content editor is #id_content. Here is a snippet of my form in ...

Issue with Promise failing to trigger .then() following fetch to Express API/Mongoose request

Can someone shed light on why I am unable to return a promise and invoke .then() on it? I am creating an inventory system for my collection of Pokemon cards using a react front-end and an express backend. When I click the "increase inventory" button on th ...

Obtain an instance of a factory object in AngularJS

How can I determine the instance of an object created using an AngularJS factory? angular.module('so') .factory('UserFac', function () { return function (first, last) { return { name : first + ...

Encountering issues with SignInWithRedirect feature's functionality

Whenever I attempt to SignInWithRedirect in my React project, I am redirected to a Google site where I only see a blue progress bar at the top before quickly being redirected back to my website. My intention is to be shown my Google sign-in options, but it ...

Troubleshooting Problems with Deploying Next Js on Firebase

I am currently working on a new Next Js application and have successfully deployed it on Vercel by linking the GitLab project. Now, I need to deploy the same project on Firebase. Here's what I have tried so far: - Ran firebase init This command gen ...

JavaScript-powered Chrome Extension designed for modifying CSS styling

Like many others, I've embarked on creating a Chrome Extension to modify the CSS of a specific webpage. Despite reading through various threads, my approach is a bit more complex than what has been discussed. The page I want to style features a sele ...

What is the procedure for re-executing the request handler in a Node.js and Express application?

Currently, my setup involves node, express, and mongojs. Here is a code snippet that exemplifies my configuration: function mongoCallback(req, res) { "use strict"; return function (err, o) { if (err) { res.send(500, err.message); } else ...

Limiting the display of JSON data on a webpage using jQuery

I have a code snippet on my website that displays JSON data on an HTML page. The issue is that there is a large amount of data in the JSON file. How can I limit the number of movies (data) being displayed to just 5? function actors(actors) { return ` ...