ScriptManager.RegisterClientScriptBlock is failing to execute the already existing script

Background

When a client-side button click triggers a server-side function, a loading panel (div) is displayed before the server-side function is executed. The loading panel should be removed once the server-side function completes.

My Approach

Upon completion of the server-side function, I plan to invoke a JavaScript function that will remove the div element. To test this, I am currently using an alert script from the master page.

Client-Side Code

Implementation of my PopUp Function:

    <script>
        function PopUp() {
        debugger;
        alert('TEST');
        }
     </script>

Script Manager:

 <asp:ScriptManager ID="ScriptManager1" runat="server">
 </asp:ScriptManager>

Server-Side Code

Code to call after completion of server-side functions:

//Add the script after <form> tag
   bool isClientScriptBlockRegistered = ClientScript.IsClientScriptBlockRegistered("ShowStatus");
   if (!isClientScriptBlockRegistered)
   {
   ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "ShowStatus", "PopUp();", true);
   }

Issue

The server is not executing my script, and the alert window is not being displayed. The script works on any page other than the master page.

Queries

Am I overlooking something?

Do I need a callback or page refresh for the alert to show, or can the server trigger the script without any client interaction?

Answer №1

Modification

ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "ShowStatus", "setTimeout(function () {  PopUp(); }, 10);", true);

transforming

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowStatus", "PopUp();", true);

RegisterClientScriptBlock inserts the JavaScript code at the top of the page right after the ViewState tag, while RegisterClientScriptBlock inserts it at the bottom. Therefore, utilizing RegisterClientScriptBlock with your PopUp() further down the page could result in an error.

By implementing a setTimeout, you ensure that all content is generated before PopUp() is executed, even if the script block is placed at the top.

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

Mastering the art of using the async pipe in conjunction with rxjs

I require assistance as the loading component of my async pipe does not activate, despite the data loading correctly. The loading template fails to trigger during subscription even though I am using a BehaviorSubject in my service. I have attempted various ...

Tips for formatting dates in Angular 6

I am currently working on a function that displays real-time dates based on user input. Currently, when the user enters the input, it is displayed in the front end as follows: 28.10.2018 10:09 However, I would like the date to change dynamically based on ...

When transferring JavaScript Array via Ajax to PHP, it results in a null response

I am attempting to send a JavaScript array to PHP, but the post data keeps returning null. Here is my JavaScript code: console.log($Seats); console.log($Seats.toString()); console.log(JSON.stringify({ $Seats })); var jsonStr = JSON.stringify($Seats); $.a ...

There seems to be an issue with [object%20Object]/undefined within the

AuthenticationService.js import axios from 'axios'; const AUTH_API_BASE_URL = "http://localhost:8087/auth"; class AuthenticationService { login(user) { return axios.post(AUTH_API_BASE_URL + "/login", user); } getRo ...

"Encountering a 504 error while trying to retrieve a file from a URL using

My attempts to read a file using a URL are resulting in a 504 Gateway Timeout error. When a user submits a form, I am supposed to extract information from a large XML file (45mb) with an XmlTextReader. However, one server consistently throws a 504 Gateway ...

Facing problem with implementing NgMoudleFactoryLoader for lazy loading in Angular 8

A situation arose where I needed to lazy load a popups module outside of the regular router lazy-loading. In order to achieve this, I made the following adjustments: angular.json "architect": { "build": { ... "options": { ... "lazyM ...

Choosing various files from separate directories within an HTML input type="file" element

Is there a way to select multiple files from various directories using the HTML input type="file" element? I have been searching for resources on how to do this without any luck. Are there any npm packages that can assist with achieving this functionalit ...

Having trouble with CSS and javascript files not resolving after moving app to a new Windows 7 development machine

I have recently migrated my ASP.Net 3.5 web site from my old XP sp3 machine to a new Win 7 64-bit dev machine. The web application utilizes Master Pages, App_Themes with style sheets and images, as well as an image folder located off the main root. Additio ...

Instructions on how to automatically play multiple video tags on one HTML page while also opening a modal

I'm working on an HTML page that needs to display two different videos in separate modals. My goal is to have each video start playing automatically when the play-video icon is clicked and the modal opens. I attempted this using the code snippet (vid ...

Is it possible to retrieve the values of #select1 and #select2 before initiating the AJAX request?

I am presented with the following snippet of HTML code: <select id="choice1"> <option value="0">Option 0</option> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3 ...

Can you provide some insight into why the init() method is throwing an error?

My project utilizes DynamoDB access through https://www.npmjs.com/package/react-native-dynamodb. I followed the code provided on the website for implementation. The issue I'm facing is that when hovering over my .init() method in WebStorm IDE, it sho ...

What could be causing my update panel to malfunction?

My update panel currently contains a checkbox and a panel. The checkbox's auto postback property is set to true, and my goal is to make the panel visible when the checkbox is checked. However, whenever I click on the checkbox, the page gets refreshed. ...

Uncovering the Secrets of Retrieving Nested Objects with MongoDB and Mongoose

I have a collection of documents stored in my mongodb database, each structured like this: { "current" : { "aksd" : "5555", "BullevardBoh" : "123" }, "history" : { "1" : { "deleted" : false, ...

Trouble installing NPM packages from Artifactory on Windows 10

Problem Description: I am utilizing Artifactory for my NPM packages. When attempting to install them on "Windows - 7", everything is functioning correctly. However, on "Windows - 10" an error is being displayed and the packages are not installing. Error M ...

What is the simplest method for invoking a C# function from JavaScript?

I am facing an issue with a LinkButton control in my project. I need to attach a c# method to it, but when I add the control to the page using parse control function, it changes the call to javascript and results in an undefined error. I have been trying t ...

Implementing callback within another function: A guide

I'm embarking on the journey of creating a node waterfall using the async module. I've just dipped my toes into the waters of asynchronous programming in node. Essentially - how do I trigger callback() within the http.request function to proceed ...

Is it possible for the Redux state to become unsynchronized?

const SortingFunction = ({ dataState, updateState }) => { const handleClick = () => { const newState = JSON.parse(JSON.stringify(dataState)) // Make necessary updates to the new state based on the current dataState updateState(newStat ...

Having trouble with submitting data in an ExpressJS POST request while using mongoose?

As I embark on building my first express.js application, I encounter my initial obstacle. The setup is rather simple. Routes in app.js: app.get('/', routes.index); app.get('/users', user.list); app.get('/products', product. ...

Having trouble locating the route for controller versioning in ASP.NET Web Api 2. Error: Route

I am working on an ASP.NET Web Api 2 application that currently has controllers. We now have new controllers that need to be added with a prefix of (v10). /api/products/1 // Old controller /api/v1/proucts/1 // the new controller I attemp ...

Tips for updating the icon based on the active or inactive status in ag-grid within an angular application

HTML* <ng-template #actionButtons let-data="data"> <div class="cell-actions"> <a href="javascript:;" (click)="assign()"> <i nz-icon nzType="user-add" nzTheme= ...