Need help resolving a JavaScript error while implementing ToolScriptManager for UpdatePanel in my project

I am attempting to register the following JavaScript code in order to add freeze functionality to a GridView. However, when trying to compile, I encounter the error message 'Microsoft JScript runtime error: 'Sys' is undefined'

How can this issue be resolved?

<script language="javascript" type="text/javascript">
    // This script is used to maintain grid scroll during partial postback
    var scrollTop;
    // Register begin request and end request 
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    // Get the div scroll position
    function BeginRequestHandler(sender, args) 
    {
    var m = document.getElementById('divGrid');
    scrollTop=m.scrollTop;
    }
    // Set the div scroll position
    function EndRequestHandler(sender, args)
    {
    var m = document.getElementById('divGrid');
    m.scrollTop = scrollTop;
    } 
</script>  

Answer №1

    <script type="text/javascript">
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_initializeRequest(initializeRequest);
        prm.add_endRequest(endRequest);
        var _postBackElement;</br>
        function initializeRequest(sender, e) 
     {
if (prm.get_isInAsyncPostBack()) 
{ e.set_cancel(true); }

    var m = document.getElementById('divGrid'); 
    scrollTop=m.scrollTop; 
    } 
    function endRequest(sender, e)
    { 
    var m = document.getElementById('divGrid'); 
    m.scrollTop = scrollTop;
    } 
            </script>



try implementing the following in web.config within <system.web>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>

Answer №2

Although this post is dated, it's crucial to point out another issue I came across in my code recently. In essence, the problem stemmed from incorrectly placing the JavaScript code, especially when working with a master page.

The solution that worked for me involved utilizing a ToolKitScriptManager in the master page with the attribute EnablePartialRendering set to "true".

Check out this reference for more information:

Please note that the provided code snippet may not be comprehensive but should offer sufficient details.

<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="server">
<div>

    <script type="text/javascript">

        var scrolltop;
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

        function BeginRequestHandler(sender, args) {
            var elem = $get("scrollableContainer");

            scrolltop = elem.scrollTop;
        }

        function EndRequestHandler(sender, args) {
            var elem = $get("scrollableContainer");

            elem.scrollTop = scrolltop;
        }
    </script>

    <asp:updatepanel id="UpdatePanel1" runat="server" updatemode="Conditional">
        <contenttemplate>
        </contenttemplate>
    </asp:updatepanel>

I hope this resolves any similar issues you may encounter!

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

Exploring Objects in jQuery using JSON Data

The following JSON data is provided: {"Name":"bb", "age":"10"} After searching extensively on the internet, most of the answers assume prior knowledge of the keys "Name" and "age", resulting in references like j.Name and j.age. My objective is to itera ...

How can one retrieve elements from a dictionary array and create a new array?

I'm struggling with how to access elements from a dictionary within an array and create another dictionary in ReactJs. The data structure is as follows: [{name: "dad", data: 10}, {name: "mom", data: 20}, {name: "dad", data: 40}, {name: "mom", da ...

Bundle Thirdparty Dependencies with Webpack

I am looking to package a webpack bundle that includes all common third-party vendors such as Angular 1.4, jQuery, and other libraries. Currently, the following modules have been developed: Module A Vendor Module Vendor Module: Create a simple module ...

Issue with splitting an array and eliminating commas - angular/ReactJS

Console Error: Unhandled error during execution of mounted hook Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'split') It seems to work up until it comes across a group that has no data for continent. This looks ...

Utilizing server-side cookies in next.js and nest.js for efficient data storage

I have been working on a small application using Next.js and Nest.js. One of the functionalities I implemented is a /login call in my client, which expects an HttpOnly Cookie from the server in response. Upon receiving a successful response, the user shoul ...

Changing the image source dynamically based on the availability of the image

I am currently working on a task that involves loading different thumbnail images based on whether a specific image exists in the system or not. The image is identified by an id as part of its name and comes from a database entry. To simplify, if the imag ...

Difficulty in incorporating reCaptcha into a PHP contact form and submitting it using AJAX

After integrating AJAX into a contact form that already had reCaptcha, I am facing issues with retrieving the g-recaptcha-response. The PHP code for reCaptcha remains unchanged from when it was functioning correctly, and I'm unsure of what modificatio ...

Adjusting the zoom level in leaflet.js ImageOverlay will cause the marker

Using ImageOverlay to display an image as a map with Leaflet.js, but encountering issues with marker positions shifting when changing the zoom level. Followed instructions from this tutorial, and you can find a code pen example here. // Code for markers ...

The Issue of Anti Forgery Token Not Functioning Properly with Ajax JSON.stringify Post

I have been attempting to utilize an Anti Forgery token with JSON.stringify, but despite researching multiple sources, I have not been successful. Below is my AJAX code for deleting some information without any issues. Upon adding the anti forgery token, I ...

Issue in Jquery: Unable to load the corresponding pages when toggling the checkbox on and off

I am facing an issue with a checkbox and calling different php pages based on the status of the checkbox. Currently, the code works only for checked checkboxes. I'm not sure why it's not working for unchecked checkboxes as well. <script type ...

Developing Your Own Local Variable in Angular with Custom Structural Directive ngForIn

I am hoping for a clear understanding of this situation. To address the issue, I developed a custom ngForIn directive to extract the keys from an object. It functions correctly with the code provided below: import {Directive, Input, OnChanges, SimpleChan ...

showing the values stored in local storage

My goal is to show only the values stored in local storage, excluding the key value that displays all data after submitting the login form. welcome <span id="demo"></span>; <script> document.getElementById('demo').innerHTML = ...

The functionality of the button is disabled once a pop-up JavaScript is implemented

I have encountered an issue with my HTML code that involves a button intended to hide certain content. The problem arose when I implemented a popup feature, causing the button to malfunction. Here is the JavaScript for the popup: $ = function(id) { retur ...

Error: React/Express - The renderToString() function encountered an unexpected token '<'

As I work on implementing server-side rendering for my React/Express application, I have hit a snag due to a syntax error related to the use of the react-dom/server renderToString() method. In my approach, I am following a tutorial mentioned here - The sn ...

Exploring the implications of Content Security Policy in conjunction with mod_pagespeed evaluations

I am currently in the process of configuring CPS rules for my website. One issue I have encountered is that mod_pagespeeds often uses 'unsafe-eval' for scripts, which goes against my security settings. An example of code generated by mod_pagespee ...

Divide the output results into two equal horizontal sections within the same HTML table

Is there a way to dynamically split the output of a specific result into two horizontal sections that fit within the browser width? The number of rows returned from the service is variable, so a fixed solution won't work. I also want to avoid manually ...

Adding Elements in Real-Time to a jQuery Mobile ListView

I'm looking to inject dynamically fetched data, formatted in JSON, into my listview. I'm struggling with how to make it work. The mobile site is fetching the object in this structure: [ {"id":1, "start":"2011-10-29T13:15:00.000+10:00", "end ...

Show the initial three divs first before implementing a toggle for the rest

My dashboard consists of multiple panels, each containing various items. Some panels have a large number of items. I am looking to display only the first three items in each panel and provide a toggle option to show/hide the rest. <div class="dashboa ...

When a block is clicked, jQuery will reveal that block while hiding the others sequentially, starting with the second block, then the third, and finally the fourth

Creating a navigation menu with 4 blocks can be a bit tricky, especially when trying to show one block at a time upon click. Here is my code attempt, but unfortunately it's not working as expected. I would greatly appreciate any help or suggestions on ...

Develop JSON Object with C# Web Service

Learning the basics of C# Web Services to handle JSON data can be quite challenging. If you have a web service that returns data in JSON format, such as the following example: {"RESULT":"2","TKN":"E952B4C5FA9","URL_HOME":"My_Url_Home"} You may encounter ...