How to Trigger an ascx.cs Function from an ascx Page with JavaScript

I'm currently working with a code behind file that includes a method:

public string ProductsAsJson()

This method is responsible for returning a JSON representation of multiple products. In order to integrate some Angular functions into my ascx page, I am attempting to call the function using the following code snippet:

 <script type="text/javascript">

   var products = <%# ProductsAsJson() %>;

Unfortunately, this approach is not successfully retrieving the list of products. Can anyone help me understand what might be going wrong?

Answer №1

One method to utilize the return value of ProductsAsJson() is by storing it in a public variable and invoking this method during page load in .cs. Afterward, you can access this variable in the ascx control and assign its value to a JavaScript variable.

var products = <%# ProductsAsJson %>;

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

Encountering issues with utilizing the mongoose model

For my current project, I am working on a basic registration form with mongoose integration. The processing of the form values is done through a separate javascript file. This is the content of my registrationButtonAction.js window.onload = function() { ...

Failure of Ajax POST requests to refresh screen content

Within my "scenario", I have numerous "forms" that consist of various "events," "data," and more. To populate all this information, I've included the following script to run once the page has fully loaded: $(document).ready(function() { var scenarioI ...

Transferring information from nopCommerce to Umbraco version 7

During the process of developing a new Umbraco website for a client, I am tasked with transferring all content (products, categories, product images, etc) from nopCommerce to Umbraco 7. To maintain relationships and mappings between products and categories ...

How to retrieve TypeScript object within a Bootstrap modal in Angular

Unable to make my modal access a JavaScript object in the controller to dynamically populate fields. Progress Made: Created a component displaying a list of "person" objects. Implemented a functionality to open a modal upon clicking a row in the list. ...

What happens to the content within a <textarea> element if it is not enclosed between the opening and closing tags?

Here's a puzzling situation - I've entered the word Hello. into a <textarea>, and while I can see it on my screen, it doesn't show up between the opening and closing <textarea> tags. It may seem like a simple issue, but I'v ...

$injector encountered a problem resolving the required dependency

Currently, I am attempting to adopt the LIFT protocol (Locate, Identify, Flat, Try(Dry)) for organizing my Angular projects. However, I am encountering difficulties in handling dependencies from other files. Here is the factory I have: (function () { ...

Ensuring type signatures are maintained when wrapping Vue computed properties and methods within the Vue.extend constructor

Currently, I am trying to encapsulate all of my defined methods and computed properties within a function that tracks their execution time. I aim to keep the IntelliSense predictions intact, which are based on the type signature of Vue.extend({... Howeve ...

Is there a method by which I can access information from a linked document in Firebase?

I am relatively new to firebase and I am attempting to retrieve data from a referenced document in another collection to display. Link 1 Link 2 This is how I add a student and the parent's ID: const newStudent = { name: req.body.name, grade: ...

Transmitting information after a delay when using ng-keyup in AngularJS

In my Angular app, I am using ng-keyup to search data from my backend. However, the issue is that it sends a request to the server with every key press. Is there a way to configure it to send a post request only after the user has paused or stopped typing? ...

What is the best way to send multiple parameters to an express server using an AngularJS service?

I sent two parameters from the client to an express endpoint and it was working fine on my local machine. However, after deploying it to a Linux server, I'm not getting any results. There are no errors or response. Could this be an issue with the para ...

Excess space within Bulma's CSS container

I am currently immersed in the world of Bulma CSS frameworks as I work on designing a contact us page. However, I have encountered a pesky issue with unwanted space that I cannot seem to eliminate, no matter how hard I try. To give you a better idea of the ...

Looking for assistance with increasing the output size in JavaScript

As a beginner in JavaScript, I managed to create a form with a textarea and a button to display the text from the textarea in a div tag. Additionally, I added two buttons that are meant to increase the size of the text in the div tag when clicked, as wel ...

Guidelines for parsing JSON data into a nested class with JSON.net

Here is my JSON data: {"customer":[{"phone":"9868133331"},{"phone":"9971714514"}],"message":[{"type":"reminder"},{"type":"reminder"}]} This JSON is structured as follows: { "customer": [ { "phone": "9868133331" }, { "phone": "9 ...

Clicking on the user will reveal a modal containing all of the user's detailed information

**I am trying to pass the correct user data to the modal ViewUser component, but it keeps displaying the same user regardless of which user I click on. How can I specify the specific user whose data should be shown? I am sending the user information as a ...

Unsynchronized state of affairs in the context of Angular navigation

Within my Angular project, I am currently relying on an asynchronous function called foo(): Promise<boolean>. Depending on the result of this function, I need to decide whether to display component Foo or Bar. Considering my specific need, what woul ...

I am experiencing issues with the Nuxt.js (SPA) application constantly crashing on iOS Safari whenever I attempt to take multiple photos. Could this be due to a memory

An innovative application I developed utilizes Nuxt.js (SPA) to efficiently process up to 20 images captured with an iPhone in one go. Upon capturing the images, they are compressed to roughly 500KB using a library known as browser-image-compression and th ...

Obtaining Browser Console Logs with Python Selenium - TCF API Integration

I am looking to extract Tracking Consent Strings (TC-strings) from websites that have implemented the Tracking Consent Framework for GDPR compliance. In the browser console, I can use the following code snippet: window.__tcfapi('ping', 2, functio ...

Navigating through an XML File in C#

Currently, I am utilizing an XMLReader to analyze a well-formed XML document. As I commence reading, I encounter an if statement as displayed below: if (reader.IsStartElement()) { // Code should be inserted here My key query is: How can I extract on ...

Organizing JavaScript Scripts for Sequential Loading

I've been using JavaScript $ajax to load multiple scripts asynchronously, but I'm facing an issue where they load in a random order instead of the specified order. Here is the current code snippet: loadScripts(); function loadScripts() { g ...

Retrieve the decimal separator and other locale details from the $locale service

After reviewing the angular $locale documentation, I noticed that it only provides an id (in the form of languageId-countryId). It would be helpful to have access to more specific information such as the decimal separator character. Is there a way to retri ...