Sending a variable to ASP using JSON parsing

In the VB Code behind, there is a function that uses parameters to output a datatable, which is then used in the front end to place markers on Google Maps. The requirement from the front end is to send a user-entered variable.

Javascript Pseudo:

if (a = true){
    var varName = inputBox.value;
    var passer1 = chkCondition1();
    var passer2 = chkCondition2();

    if (passer1 == true && passer2 == true) {
        Coordinates = JSON.parse('<%=ConvertTabletoString(varName) %>');
    }
else {
    //do other stuff
     }

An error message is appearing:

Error 2 'varName' is not declared. It may be inaccessible due to its protection level.

The solution to this issue is currently unclear. Is there any alternate way to proceed?

Answer №1

The root cause of the issue you are facing is that the variable required on the server-side is non-existent both on the server and the client side at the specific point you are trying to access it. Essentially, you are attempting to access a variable on the server that will only be created on the client side, but your attempt is made before any content is rendered in the user's browser.

  1. To resolve this, utilize AJAX to send the value to the server-side.

  2. Implement a server-side API function that can process your command upon arrival to the server and provide the necessary JSON data back to the client-side.

  3. Parse the response JSON within your AJAX callback function.

  4. Reap the benefits.

Answer №2

The reason for the error is due to "varName" being a client-side variable.

If "inputBox" is a server control, you can retrieve its value directly from the ConvertTabletoString() method.

If not, consider using a hidden field with runat="server" and assign inputBox.value to it. This way, you can access the hidden field's value within your server-side method.

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

Moving object sideways in 100px intervals

I'm struggling to solve this issue. Currently, I have multiple div elements (each containing some content) that I need to drag and drop horizontally. However, I specifically want them to move in increments of 100px (meaning the left position should b ...

Verify that each interface in an array includes all of its respective fields - Angular 8

I've recently created a collection of typed interfaces, each with optional fields. I'm wondering if there is an efficient method to verify that all interfaces in the array have their fields filled. Here's the interface I'm working wit ...

Poorly formatted JSON encoding

Looking to extract JSON data from a text file? Here's the content of the file: [19-02-2016 16:48:45.505547] [info] System done. 0: array( 'ID' => 'Example 2' ) This is the code snippet I'm using to parse the file: $ ...

Should the hourly charge schedule be based on user input and be created from scratch or utilize existing templates?

I have hit a roadblock while creating a charging schedule based on user input for my project. I am debating whether to search for and modify an existing plugin or develop it from scratch. The schedule involves solar charging electric cars between 7am and ...

Transferring event arguments to JavaScript in ASP.NET C# through OnClientClick

Currently, I have an asp button on my webpage. In the code behind within the Page_Load method, I am assigning some JavaScript calls in the following manner. btnExample.OnClientClicking = "functionOne(1,2);"+"function2()"; However, I am encountering a pro ...

Working with JSON arrays in Android and extracting specific elements from them

I am looking to extract information from the userinfo Array along with some strings in it, as well as the getuserlistdata Array and associated strings. Can someone assist me on how to parse this response? Here is a snippet of my code: { "statu ...

When running the PHP script, the output is shown in the console rather than in the

Here is a PHP script snippet that I am working with: <?php add_action('wp_ajax_nopriv_getuser', 'getuser'); add_action('wp_ajax_getuser', 'getuser'); function getuser($str) { global $wpdb; if(!wp_verif ...

Tips for customizing the appearance of popup windows

I want to enhance the appearance of my popup window by applying a different format for opening it. How can I style it so that it looks visually appealing when the popup window opens? You can find below the source code I am working with: HTML: <div onM ...

What is the best way to display recently added information?

I'm curious about why the newly added data isn't showing up in the template, even though it does appear when using console.log (check out ViewPost.vue). After adding a new post, this is the result: result.png. Does anyone know how to fix this? ...

Tips for ending a session after modifying <li> in ASP.Net

My horizontal menu is designed using ul il and I am facing an issue with converting my Login link to Logout in the list. <div class="menu"> <ul> <li><a href="Home.aspx">Home</a></li> < ...

Generating HTML files using Express and body-parser

I need assistance with incorporating user login data into an existing HTML document using Express. The input from the username field should be displayed at the top of the page. How can I access specific elements in the HTML document through Node or Express ...

Rapidly refreshing user interface in real-time based on current status

I'm struggling to create a button that will smoothly open a menu. Initially, I thought setting the state on button click would work fine but now I realize that the first click does not have any effect on the state or class. It's only the second a ...

Fantastic tutorials for mastering the ASP.Net security and authentication framework

For years, I avoided learning the built-in ASP.Net support for web application authentication, users, and roles by sticking my head in the sand, reinventing the wheel, and being stubborn. I preferred rolling my own solution because dealing with all the abs ...

"Can someone help me figure out why the onPress function is not functioning as

Every time I press the button, I attempt to send a request using jQuery. Surprisingly, it works fine on the snack UI but when I try it on the expo client, an error pops up saying undefined is not a function (near '...jquery.default.ajax...'). Odd ...

Testing an npm module that relies on DOM elements can be done by simulating the browser

As a newcomer to developing npm modules, I am currently working on creating my first one. My goal is to have it easily included in the browser using a script tag, accessible via npm install command, and testable by opening an HTML page with the code includ ...

Generating dynamic arrays in JavaScript

View the working code here: http://jsfiddle.net/sXbRK/ I have multiple line segments with unique IDs, and I know which ones intersect. My goal is to create new arrays that only contain the IDs of the overlapping line segments. I do not need the IDs of l ...

Is jquery.validate necessary for Unobtrusive validation in .NET 4.5?

Currently, I am developing a project using ASP.NET web forms and I am a bit unsure about which jQuery libraries are required for the .NET 4.5 unobtrusive validation. Some sources suggest that I need to include just jquery, while others recommend adding j ...

Tips for steering clear of bind or inline arrow functions within the render method

It is recommended to avoid method binding inside the render function because it can impact performance. Each time the component re-renders, new methods are created instead of using existing ones. In situations like this: <input onChange = { this._hand ...

A guide to effortlessly converting Any[] to CustomType for seamless IntelliSense access to Properties within Angular/Typescript

Our Angular service interacts with the backend to retrieve data and display it on the UI. export interface UserDataResponse { id: number; userName: string; } AngularService_Method1() { return this.http.get<UserDataResponse[]>(this.appUrl + "/Ap ...

Utilizing Gitlab CI-generated Artifact for API Request - A Guide

Currently, I am utilizing a Go microservice that requires parsing a Newman report. Initially, I fetch the Newman report from the local directory using the following code: jsonFile, err := os.Open("outputfile.json") if err != nil { fmt.Println ...