Accessing a JSON string correctly using JavascriptSerializer in JavaScript

When working with JavaScript, I encountered an issue where the data retrieved from a data table and converted to javascriptSerializer was not refreshing correctly when changing dataset selection parameters. The problem occurred when trying to populate a new set of data using the PopulateChart() function again.

Despite receiving the correct data on the server side and generating the appropriate JSON string, the old data persisted in the client-side var chartData.

Below is the code snippet showcasing the issue:

ASPX

var chartData = <%= PopulateChart() %>;

VB

Public Function PopulateChart() As String

    ''Get Chart Data
    Dim daChart As New dsSVTableAdapters.clsChart
    Dim dtChart As New dsSV.webV1_ChartsDataTable
    Dim drChart As dsSV.webV1_ChartsRow

    dtChart = daChart.GetChart(hChartID.Value)

    If dtChart.Rows.Count > 0 Then

        'Code for populating chart data goes here'

        serializer.MaxJsonLength = Int32.MaxValue

        Return serializer.Serialize(rows)
    End If

End Function

Answer №1

Instead of relying on server-side evaluation at each page load with <code><%= PopulateChart() %>
, consider using ajax calls or full page reloads to update chart data in JavaScript on the client side.

You can refer to an article on CodeProject that discusses ASP.NET and AJAX implementation using jQuery for more insights: http://www.codeproject.com/Articles/17203/Using-jQuery-for-AJAX-in-ASP-NET

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

What mechanism does the useState() function utilize in React to fetch the appropriate state object and function for a functional component when employing the state hook?

Currently focusing on deepening my understanding of the useState hook in react. I have a question regarding how useState retrieves the state object and modifier function specific to each functional component when it is called. What I'm wondering is w ...

Utilizing Android to Retrieve JSON Data from a Web Address

Currently, I am working on converting my website into an Android app and one of the pages on my website displays data populated via JSON. The URL generates different JSON data with the same structure based on the passed ID. I have already implemented the l ...

Mocha test failing to trigger function execution

I've been developing an Express.js application that includes a feature for creating appointments with a post request. This feature involves retrieving and saving data from a third-party API, followed by sending updated API data in the subsequent reque ...

Toggle a button with javascript

My setup involves two switches: <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="switch1" checked> <label class="onoffswitch-label" for="switch1"> <span class="onoffswitch-inner"></span> <span ...

I am encountering a horizontal scroll bar despite setting the width to 100%

I am just starting out as a beginner in web development. I decided to create a webpage to practice my HTML and CSS skills. However, when I set the width of all elements to 100%, I noticed that I am getting a horizontal scroll bar. I have tried troubleshoot ...

Is it possible to dynamically change a form's input value using a JavaScript keyup function based on input from other form elements?

My form utilizes the keyup function to calculate the total value of 3 input fields by multiplying them and displaying the result. Below is a fiddle showcasing this functionality: $(document).ready(function () { $(".txtMult1 input").keyup(multInp ...

Exploring the concept of multiplying JSON arrays in Java can lead to a deeper understanding of how to

Seeking guidance on performing JSON Array Multiplication in Java. I'm attempting to multiply two JSON Arrays, [1,2] and [1898,0987]. Assistance would be greatly appreciated. ...

What could be the reason why the toggleClass function is not being run

I've been running into a little issue with using the .toggleClass function in my code. It seems to work inconsistently, and despite reading various posts on the topic, I haven't found a solution that works for me. Could you provide some assistan ...

Reviewing and Implementing React and Material-UI Autocomplete for Selecting Multiple

Having trouble using Formik and MUI Autocomplete with multiple items. Specifically, when searching for "Pencil", it doesn't highlight the item. Also, you can select it twice by clicking on it. Desired outcome: Being able to select one or more items. ...

Issue: The variable '$viewMap[...]' is either null or undefined

Unfortunately, my knowledge of jQuery/Javascript is quite limited. I am encountering a Javascript error when trying to change the "how did you hear about us" dropdown on a form. The error message states: Error: '$viewMap[...]' is null or not an ...

Having trouble receiving a JSON array after making an Ajax request

I have read through previous posts on this issue, but I still can't seem to figure it out. Hopefully, someone here can help me solve this problem. My challenge lies in retrieving an array, which I have encoded in json, from a PHP script and passing i ...

Fill a dropdown menu in HTML with data from a parsed JSON object array

Can someone help me with populating an html select element from the JSON data below? I can't figure out how to use a for each loop with this type of json data. Thanks! //JSON [{ "group": "US (Common)", "zones": [{ "value": "America/P ...

The JSON array successfully retrieves the data, however, it is unable to be formatted and displayed

I am having trouble displaying JSON data from an online source in my app. Although the data is being retrieved successfully, it does not appear on the activity where it should be displayed. I suspect there might be an issue with how I am populating the lis ...

Picked (chosen-js): Steps to deselect options using a variety of selectors

I am currently using the Chosen library on Vue and Webpack for my project. I have a scenario where I need to cancel a selection when multiple options are selected, but I am struggling to achieve this. Can anyone guide me on how to cancel a selected optio ...

Can a complete form be encapsulated within a single AngularJS directive?

While I have come across several instances of individuals utilizing a blend of HTML and directives to craft an AngularJS form (as seen here), my goal is to develop a self-contained widget. This widget would encompass all the necessary HTML for the form w ...

"Duplicate content issue with ng-transclude causing element to render twice

Why is the transcluded directive displaying Name inside directive = Frank twice? I believed I had a good grasp on transclusion, but this specific scenario has left me puzzled. Check out this fiddle for more details <div ng-app="myApp" ng-controller=" ...

Navigating a FormData object in javascript on a .NET WebAPI version 5.2.2

I am currently working on integrating webcam video recording upload using the example provided in this RecordRTC GitHub repo. However, I have encountered a compiling error when trying to use "Request.Files" as indicated in the screenshot below. The error ...

Discover the myriad of possibilities created by combining arrays

I am working on a code snippet that aims to generate an array containing all possible combinations between two or more arrays. However, I am encountering a specific issue. getCombn(arr: string | any[], pre?: string | undefined) { pre = pre || ' &a ...

Ways to utilize two distinct XPATH values for a single key

When dealing with Xpath for the same object in two different portals, the paths can be: //*[@id="abc"]/fieldset/div/div/div[1]/label //*[@id="xyz"]/fieldset/div[1]/fieldset/div/div/div[1]/label In order to use both values in the same key and have Seleni ...

Error 2300 in Vetur: Identical identifier found for '(Missing)'

Recently, I've been encountering a strange issue with Vetur in my typescript nuxt.js project. Every component, whether it's just an empty line or contains code, displays an error message on the first line. I can't pinpoint when this problem ...